开发者

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

开发者 https://www.devze.com 2023-03-28 08:00 出处:网络
Say, I just ran this command in Vim: 开发者_如何学Python:nmap <CR> <C-]> And now I want to copy this line and put it into my .vimrc.

Say, I just ran this command in Vim:

开发者_如何学Python:nmap <CR> <C-]>

And now I want to copy this line and put it into my .vimrc. How can I select and copy the whole line in command-line mode?


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

":p

in Normal mode.

If the command is further back in time, one can first recall it from history (e.g., by typing the first few letters and pressing the up arrow key ), 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). 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.


You can type Ctrl-F while in command mode to open up a special window with all previous commands. Then you can scroll to the desired line, hit yy to copy that line, then press Ctrl-C to return to command mode, and then ESC to return to normal mode. From there you can paste.

See :help cmdwin for more information on the command window.

0

精彩评论

暂无评论...
验证码 换一张
取 消