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

How do I paste text and leave the cursor after the pasted content instead of on it?

Answer

gp

Explanation

The standard p command pastes text after the cursor but leaves the cursor at the beginning of the pasted text. The gp command does the same paste but leaves the cursor just after the end of the pasted content. This is especially useful when pasting multiple times in sequence or when you want to continue editing right after the pasted block.

How it works

  • gp — paste after the cursor and move the cursor to the line after the pasted text (for linewise pastes) or the character after the pasted text (for characterwise pastes)
  • gP — same as gp but pastes before the cursor

With linewise yanks (e.g., yy), gp places the cursor on the first line below the pasted block. With characterwise yanks, the cursor lands on the character immediately after the last pasted character.

Example

Starting with (cursor on line 2, after yanking line 1 with yy):

alpha
beta
gamma

Using p on line 2:

alpha
beta
alpha
gamma

Cursor is on the pasted alpha (line 3). With gp instead, cursor moves to gamma (line 4), ready for the next action.

Tips

  • gp is ideal for pasting a block of text between existing lines and continuing to work below
  • Pair with "agp to paste from a named register and jump past the result
  • gP is useful for prepending content and continuing to type after it

Next

How do I ignore whitespace changes when using Vim's diff mode?