Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vim copy command to clipboard / buffer

Tags:

vim

How to copy the ex command to the clipboard or paste it to the buffer?

Using gvim on Windows.

like image 382
Ayman Avatar asked Sep 07 '09 10:09

Ayman


People also ask

Can you copy from Vim to clipboard?

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. Go to any external application and CMD + v to paste.

How do I copy and paste from clipboard in Vim?

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.

How do I copy an entire file to the clipboard in vi?

Another easy way to copy the entire file if you're having problems using VI, is just by typing "cat filename". It will echo the file to screen and then you can just scroll up and down and copy/paste.


4 Answers

The windows clipboard can be accessed through the buffer +. So pasting your clipboard as an ex-command can be done with <C-R>+. If you want to copy your ex-commands to the clipboard, you need to show the command history (q:) and copy it into the clipboard buffer ("+yy).

like image 55
soulmerge Avatar answered Oct 10 '22 03:10

soulmerge


Enter command history with (from normal mode)

q:

Then select and copy(yank) commands you need with

"*y
like image 44
Maxim Kim Avatar answered Oct 10 '22 03:10

Maxim Kim


:call setreg('+', getreg(':'))
like image 9
skurczybyk Avatar answered Oct 10 '22 03:10

skurczybyk


To copy the last executed command to your clipboard:

:let @+=@:

Essentially assign the command (:) register to the system clipboard (+) register.

like image 10
Saad Malik Avatar answered Oct 10 '22 01:10

Saad Malik