Cursor position after pasting in vi / vim

vivim

One thing that has always bothered me in vi / vim:

If I "yank" (a.k.a. "copy") some text, then move to another place in the file and do a "paste", my cursor remains at the beginning of the text I just pasted. This is different from what most modern editors do, which is put the cursor at the end of the text I pasted.

For example, assuming the "copy buffer" contains the word "awesome" which I want to paste after the word "an" in the phrase:

This is an editor

In, for example gedit, after the paste:

This is an awesome editor
                  ^ Cursor is here

In vi:

This is an awesome editor
           ^ Cursor is here

Can I change vi to act like (for example) gedit in this regard?

Best Answer

In vim, use gp and gP instead of p and P to leave the cursor after the pasted text. If you want to swap the bindings, put the following lines in your .vimrc:

noremap p gp
noremap P gP
noremap gp p
noremap gP P

Strangely, in vim, p and P leave the cursor on the last pasted character for a character buffer, even in compatible mode.

I don't know how to change this in other vi versions.