1

I'm trying to find and answer using search but nothing's working. What I try to do: I'm editing a part of a html file using VIm, by creating a local file. Then, from VIm, I'd like to copy all (Ctrl+A in windows, sorry for the reference), then paste all in the web browser form to update the web page (it's a CMS based form, when we can use WYSIWYG but I prefer HTML).

I've tried to use this commande: gg"*yG to yank all, but when I paste in the web browser, it pastes an old thing that was in the clipboard (I guess).

I've also tried this solution (How to paste text from Vim editor to browser?) Select the text without pressing a shortcut key and middle-click in the browser window, or Select the text, press shift-ctrl-c and then use ctrl-v to paste ...

But doesn't work.

I'm on Ubuntu Workstation 14.04 LTS, maybe I've not installed the correct VIm package, in any case can yout ell me how to check it? And maybe how to copy all my file in VIm to paste it in Firefox form.

Thank you for your precious help!

3
  • "* is the X11 native cut buffer. If you past with CTRL-V you should use "+. I tested with this comment and it seems to work. So the full command is gg"+yG
    – Rmano
    Commented Feb 5, 2015 at 9:44
  • You can also find useful this firefox extension: addons.mozilla.org/en-US/firefox/addon/its-all-text
    – Rmano
    Commented Feb 5, 2015 at 9:47
  • Thank you for your answer, I tried it, in VIm I get the "140 Lines yanked" but then when I try to paste it the browser, I've got the same result... That's why I was thinking that my VIm package is not fully installed or something else...
    – tasseb
    Commented Feb 5, 2015 at 10:05

2 Answers 2

4

You can use xclip. Lets say you have a file named file.txt and you have edited the file using vim and saved it. Now running the following will copy the content of the file to the clipboard:

cat file.txt | xclip -selection c

Now you can just paste the content of the file by any usual method.

Remember, in this solution you need to save the changes you made before copying to clipboard.

2
  • That's work great, thank you! Then if someone has a VIm command to do it, I'd love to hear about it!
    – tasseb
    Commented Feb 5, 2015 at 10:10
  • @tasseb: happy to help.....
    – heemayl
    Commented Feb 5, 2015 at 10:10
1

There are many ways to do this is vim, i use this method.

Run these commands in vim

:vmap <F6> :!xclip -f -sel clip<CR>
:map <F7> :-1r !xclip -o -sel clip<CR>

Now F6 is mapped to copy and F7 is paste.

Use V to select lines and use navigation buttons to mark the lines you want to copy. While hightlighted press F6 to copy into clipboard buffer.

Now you can paste the text in any program.

Press F7 while in command mode to paste into vim.

To make the keybinding persistent you can add these lines to your $HOME/.vimrc file

vmap <F6> :!xclip -f -sel clip<CR>
map <F7> :-1r !xclip -o -sel clip<CR>

You should also see: http://vim.wikia.com/wiki/GNU/Linux_clipboard_copy/paste_with_xclip

5
  • Hey it seems to be a sexy method, I tried it but it doesn't work, for example I think it hasn't map to F6 because when I try it after entering the command, the F6 makes the window dissapear (minimize)... But it's really interesting if I manage to set it up!
    – tasseb
    Commented Feb 6, 2015 at 10:56
  • You are probably experiencing conflict in your keybindings. This means that F6 is probably mapped in your window manager already. You can try another button. <F8> for example or shift + F7 which is <S-F7>.
    – stalet
    Commented Feb 6, 2015 at 11:12
  • All the functions buttons seems to be set! It's a bit messy, is there another way to map or create a magic shortcut?
    – tasseb
    Commented Feb 6, 2015 at 11:19
  • You can try more specialized keybindings to avvoid the default set ones, like Control + F7 for example. <C-F7>. Or avvoid using F keys altogether and go for keys like Control + k - its coded as <C-k>
    – stalet
    Commented Feb 6, 2015 at 11:24
  • Try this: :vmap <C-k> :!xclip -f -sel clip<CR> and press V and go down a few lines and press Ctrl + k then it yanks the lines into xclip.
    – stalet
    Commented Feb 6, 2015 at 11:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .