简体   繁体   English

如何在 Vim 中从命令行模式复制文本?

[英]How to copy text from command-line mode in Vim?

Say, I just ran this command in Vim:说,我刚刚在 Vim 中运行了这个命令:

:nmap <CR> <C-]>

And now I want to copy this line and put it into my .vimrc .现在我想复制这一行并将其放入我的.vimrc中。 How can I select and copy the whole line in command-line mode?如何在命令行模式下 select 并复制整行?

The fastest way is to run the command, switch to the destination buffer (with .vimrc loaded, in this case) and paste the whole command from the : register by typing最快的方法是运行命令,切换到目标缓冲区(在这种情况下加载了.vimrc )并通过键入从:寄存器粘贴整个命令

":p

in Normal mode.在普通模式下。

If the command is further back in time, one can first recall it from history (eg, by typing the first few letters and pressing Up ), rerun it, and then use the above method.如果该命令的时间更早,可以先从历史中调用它(例如,通过键入前几个字母并按向上键),重新运行它,然后使用上述方法。

When these shortcuts are unhandy, one can resort to the general approach of using the command-line window (see :help cmdwin ).当这些快捷方式不方便时,可以求助于使用命令行 window 的一般方法(请参阅:help cmdwin )。 To open it, either type q: in Normal mode, or press the key combination set by the cedit option ( Ctrl + F , by default) in Command-line mode.要打开它,请在普通模式下键入q: :,或在命令行模式下按cedit选项设置的组合键(默认为Ctrl + F )。

You can type Ctrl - F while in command mode to open up a special window with all previous commands.您可以在命令模式下键入Ctrl - F以打开带有所有先前命令的特殊 window。 Then you can scroll to the desired line, hit y y to copy that line, then press Ctrl - C to return to command mode, and then ESC to return to normal mode.然后您可以滚动到所需的行,按y y复制该行,然后按Ctrl - C返回命令模式,然后按ESC返回正常模式。 From there you can paste.从那里你可以粘贴。

See :help cmdwin for more information on the command window.有关命令 window 的更多信息,请参阅:help cmdwin cmdwin。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM