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!

tasseb
  • 61

2 Answers2

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.

heemayl
  • 93,925
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

stalet
  • 589