A simple recipe to demonstrate the behavior of pasting in Vim/Vi...
dd
(delete line)p
(paste)Notice the pasted line is inserted below where you might expect it to be placed.
Why is Vim/Vi programmed with this behavior, and is there any way to change it? (ie: Have the line pasted one line above the default position.)
So if you need to copy lines in vim, you yank them and if you want to paste, you put them on a specific location. The copy paste operation in vim is achieved using: yy or Y : copies/yanks the current line, including the newline character at the end of the line.
Use P
. It will paste above the cursor instead of below.
p
will paste below the current line, P
will paste above the line. If you want you can swap the behaviors of P
and p
add the following to your vimrc.
nnoremap p P
nnoremap P p
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