I used to use "+y
to copy text to system's clipboard, but it doesn't work in vim of Bash on Windows.
In vim command mode press v , this will switch you to VISUAL mode. Move the cursor around to select the text or lines you need to copy. Press y , this will copy the selected text to clipboard.
Press v to select characters, or uppercase V to select whole lines, or Ctrl-v to select rectangular blocks (use Ctrl-q if Ctrl-v is mapped to paste). Move the cursor to the end of what you want to cut. Press d to cut (or y to copy). Move to where you would like to paste.
You need to make sure clipboard is activated (which is probably not the case). if you get "-clipboard" then you would have to install vim again with the "clipboard" functionality. You can do it it by installing "vim-gtk3" or "gvim".
Since neither "*y nor "+y (...) work, an alternative is the following:
Add this to your .vimrc
and create a file called ~/.vimbuffer
" copy (write) highlighted text to .vimbuffer vmap <C-c> y:new ~/.vimbuffer<CR>VGp:x<CR> \| :!cat ~/.vimbuffer \| clip.exe <CR><CR> " paste from buffer map <C-v> :r ~/.vimbuffer<CR>
Higlight any text using visual or visual-block and press ctrl-c
. Paste copied text outside your terminal using the usual method or paste copied text to any vim pane using ctrl-v
in normal or visual mode.
Ctrl-c
yanks the selected text, overwrites ~/.vimbuffer
with the selected text, runs a UNIX command to pipe out the data from ~/.vimbuffer
to clip.exe.
Any further improvement (e.g.: making command silent) is much appreciated!
Edit: command can now copy strings with any length, not just whole lines. Old command:
vmap <C-c> :w! ~/.vimbuffer \| !cat ~/.vimbuffer \| clip.exe <CR><CR>
Edit2: @Tropilio below has a much cleaner approach down in the comments using system events. I've been using that for a year now.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With