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
pputs text from the unnamed register after the cursor position- If the register holds linewise text (from
yy,dd, etc.),ppastes it on the line below - If the register holds characterwise text (from
yw,dw, etc.),ppastes 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
]pto paste and auto-indent to match the surrounding code - Use
"0pto paste from the yank register, which is unaffected by delete operations - Use
"+pto paste from the system clipboard - Combine
ddpto quickly swap the current line with the one below it