vimtricks.wiki Concise Vim tricks, one at a time.

How do I paste text below the current line?

Answer

p

Explanation

The p command pastes (puts) the contents of the default register after the cursor. When the register contains a whole line (from yy or dd), p pastes it on a new line below the current one.

How it works

  • p puts text from the unnamed register after the cursor position
  • If the register holds linewise text (from yy, dd, etc.), p pastes it on the line below
  • If the register holds characterwise text (from yw, dw, etc.), p pastes it after the cursor on the same line

Example

Given the text:

first line
second line
third line

With the cursor on first line, press yy to yank it, then move to second line and press p:

first line
second line
first line
third line

Tips

  • Use P (uppercase) to paste above the current line or before the cursor
  • Use ]p to paste and auto-indent to match the surrounding code
  • Use "0p to paste from the yank register, which is unaffected by delete operations
  • Use "+p to paste from the system clipboard
  • Combine ddp to quickly swap the current line with the one below it

Next

How do I edit multiple lines at once using multiple cursors in Vim?