Say, I just ran this command in Vim:
: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?
In vim command mode press v , this will switch you to VISUAL mode. Move the cursor around to select the text or lines you need to copy. Press y , this will copy the selected text to clipboard.
Now you can select text using your mouse or the keyboard (hold down the Shift key and use the left or right arrows to select words). Press CTRL + C to copy it, and press CTRL + V to paste it in the window. You can also easily paste text you've copied from another program into the command prompt using the same shortcut.
To copy from a terminal window press CTRL-W N (This is a capital N)1 or CTRL-\ CTRL-N (this is not a capital N) to get into normal mode. From there you can use all usual vim commands to copy and paste stuff. Entering insert mode will drop you back to your shell.
You can use :set mouse& in the vim command line to enable copy/paste of text selected using the mouse. You can then simply use the middle mouse button or shift insert to paste it.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With