首页 > 解决方案 > 如何从 Vim 命令行复制文本

问题描述

此处询问了如何粘贴到 vims 命令行中 。但是如何从 vim 命令行复制呢?

例如:

:python 导入系统;打印(sys.executable)

现在我想将该行复制到剪贴板,以便将其粘贴到其他编辑器中。

标签: vim

解决方案


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

推荐阅读