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

How do I paste text before the cursor while leaving the cursor positioned after the pasted content?

Answer

gP

Explanation

The gP command works like P (paste before the cursor) but leaves your cursor after the pasted text rather than at its beginning. This makes it easy to chain multiple pastes or to continue editing immediately after inserted content.

How it works

  • P — paste before cursor; cursor lands on the first character of the pasted text
  • gP — paste before cursor; cursor lands after the last character of the pasted text

The lowercase variant gp gives the same cursor-after behaviour for after-cursor pastes (p).

Example

Suppose you have yanked the word hello and your buffer contains:

world

With the cursor on w, pressing P produces:

helloworld

and leaves the cursor on h. Pressing gP instead produces the same text but leaves the cursor on o (the last pasted character), ready for you to continue typing or paste again.

Tips

  • Use 3gP to paste three copies in a row; the cursor ends up after all three, not at the start of the first.
  • Pair with a named register: "agP pastes from register a before the cursor, cursor after.
  • The symmetric command gp (lowercase) does the same for after-cursor pastes.

Next

How do I use a count with text objects to operate on multiple text objects at once?