Often I need to paste something into several adjacent lines, at the same or similar positions. It's a pain to have to move the cursor back to the beginning of the pasted contents every time, when moving on to the next line. How can I paste (as in, the command 'p') without moving the cursor? Or, how can I quickly get the cursor back to where it was before pasting?
Press y to copy, or d to cut the selection. Move the cursor to the location where you want to paste the contents. Press P to paste the contents before the cursor, or p to paste it after the cursor.
Options: 1) Use yy to yank the whole line (including the end of line character). p will then paste the line on a new line after the current one and P ( Shift - P ) will paste above the current line.
Pasting in VimOnce you have selected text in Vim, no matter whether it is using the yank or the delete command, you can paste it in the wanted location. In Vim terminology, pasting is called putting and the function is utilized with the p command. Using this command pastes the selected text after the cursor.
The safest way without destroying a register is to do the following:
p`[
If you want to create a shortcut, just use any of vim's map functions that is suitable for you, eg:
noremap p p`[
Whenever I have a sequence of steps to repeat several times I record a macro, which is trivially easy in Vim. The general method is
So in your case, the entire sequence of keystrokes to record the macro might be
qxp`[jq
and 5@x
to replay it five times for a total of 6 changes.
Note that the character after the first q is a register to record the macro into and it can be any letter, not just x. Just be careful your macros doesn't yank text into the register presently being recording into, it makes a real mess of things!
Macros can be arbitrarily long and complex. They can contain Ex mode commands and even call other macros.
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