1

How to paste into vims command line was asked here here. But how can I copy from the vim command line?

For example:

:python import sys; print(sys.executable)

Now I want to copy that line to the clipboard, for pasting it into an other editor.

newandlost
  • 935
  • 2
  • 10
  • 21

3 Answers3

2

You can assign to a register the content of another register:

:let @+ = @:

Will assign in the system clipboard (@+) the last executed : command (@:).

However, this will become your last executed command. If you want to keep your python command as the last one, you can do the following:

First open the command history:

q:

Go on the line of the command you want to copy, then yank it in the system register (visually selects the whole line and yanks it):

"+yy

This will copy the whole line with the new line character at the end, if you just want the command without the new line, you can do:

v$h"+y

Finally, close the command history:

:q
padawin
  • 4,230
  • 15
  • 19
  • Indeed, actually, what I wanted to achieve was to copy without the new line character, but it should then be `v$h"+`. I guess it depends on if the OP wants the command with a new line or not – padawin May 15 '19 at 08:12
2

Yes, it is possible.

If you executed a command :foo, the command text line will be stored in register :, you can see it by :echo @:.

To have those value in clipboard, you just let + register have the same value.

So :let @+=@: or call setreg('+',@:) should help you.

Kent
  • 189,393
  • 32
  • 233
  • 301
  • But it is only the last command or? I can not scroll through history (arrow up) and then copy the one that I stoped at? – newandlost May 12 '19 at 13:48
  • @newandlost one way is `q:` in normal mode or `:ctrl-f` in command mode, to enter command window, you can yank/copy the previous command you want there – Kent May 13 '19 at 14:19
1

q: open command-line window, it's filled with command-line history, you can copy via "+yy.

dedowsdi
  • 209
  • 2
  • 8