The command p pastes below the cursor and P pastes above the cursor. What\'s the command to paste in the line where cursor is?
divide the line into 2 wherever you want to insert
paste the section between them
merge the 3 lines with j as described here (Delete newline in Vim)
works, but tedious, and had to think about, look it up => vi and emacs are garbage software
If you want to keep the current line as it is, you either paste above or below the line.
If you want to overwrite the current line you'll have to delete it first, which means that the following line takes its place, then paste above the new current line.
There are more than one way to do it:
"_ddP
"_dd
deletes the whole current line in the "black hole register", the following line is now the current line.
P
puts the content of the unnamed register above the current line.
Vp
V
puts you in VISUAL LINE mode and selects visually the whole current line
p
replaces the selection with the content of the unnamed register
S<C-r>"
S
deletes the content of the current line and puts you in INSERT mode
<C-r>"
puts the content of the unnamed register
The two last options have an interesting side effect: the content of the previous line is put into the unnamed register which makes it impossible to do multiple pastes with the same content.
Luckily, you can work around this situation:
The "black hole register", mentioned in the first solution works, well… like a black hole. Whatever you put into it disappears forever so you can continue using p
and P
with some degree of confidence that the unnamed register is still the same from paste to paste.
Vim gives you access to 26 alphabetic registers that you can use to save macros or… paste stuff repeatedly.
Taking the second solution as a starting point, you start by yanking a whole line into register "a
with "ayy
then you do V"ap
on another line.
But all of the above assumes that the text you want to paste is an actual line. Vim makes the difference between "line-wise" and "character-wise" : it won't let you paste a line in a character-wise context or the other way around.
Yanking a whole line with yy
keeps its line-wiseness or character-wiseness and you won't be able to p
between two characters on a same line. For that you need to make sure that what you yank won't be interpreted as line-wise by Vim. For example, let's assume you are on the first character of the first line and want to yank ipsum dolor
and put it at its normal place between lorem
and sit
:
ipsum dolor
lorem sit amet
You should type "ayee
to put your yanked text in register "a
, place the cursor where needed and type "aP
.
You can use D to delete from current cursor position to the end of line, and the p to the new cursor position.
That is to cut and paste a whole line use ^D and p.
The Edit menu in gvim lists the following:
Paste = "+gP
Put Before = [p
Put After = ]p
If you're running vim in Windows, you can do the following to get Ctrl+C and Ctrl+V to work as expected:
source $VIMRUNTIME/mswin.vim
behave mswin