Ayman
Ayman

Reputation: 11585

vim copy command to clipboard / buffer

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

Using gvim on Windows.

Upvotes: 42

Views: 15340

Answers (6)

Saad Malik
Saad Malik

Reputation: 1648

To copy the last executed command to your clipboard:

:let @+=@:

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

Upvotes: 13

cure
cure

Reputation: 2688

not exactly an answer to the question, but on the same lines, the command    ":p    will put/paste the last ex command into the file. it can then be yanked into the clipboard with the command     V"+yy
neither of these will open another window.
they are also useful for when you come up with a really good really long command that you want to save.

Upvotes: 3

skurczybyk
skurczybyk

Reputation: 117

:call setreg('+', getreg(':'))

Upvotes: 9

soulmerge
soulmerge

Reputation: 75704

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).

Upvotes: 46

Maxim Kim
Maxim Kim

Reputation: 6392

Enter command history with (from normal mode)

q:

Then select and copy(yank) commands you need with

"*y

Upvotes: 20

Brian Rasmussen
Brian Rasmussen

Reputation: 116401

If you source mswin.vim in your setup it will map the default Windows copy/paste keys to use the clipboard. If you want to do it yourself please see Soulmerge's answer.

Upvotes: 0

Related Questions