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?

  • What is even more weird, at list with my version of Vim: if the yanked text spans more that one line, then the cursor is left at the beginning of the pasted text, otherwise it is left at the end of the pasted text.
    – Alexey
    Commented Dec 10, 2013 at 11:13
  • sorry, at least
    – Alexey
    Commented Dec 10, 2013 at 11:45

4 Answers 4


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.

  • 1
    I think "vi" is usually really "vim" in most distros, right?
    – JoelFan
    Commented Dec 21, 2010 at 20:06
  • @JoelFan: Most non-embedded Linux distros, maybe. Elsewhere, no. If you're ok with a vim-only solution, don't bring vi into the play: 99% of vim's configurability is not in basic vi. Commented Dec 21, 2010 at 20:18
  • Waht about "nvi"? I'm confused about all the different vi's. I am mostly insterested in debian and ubuntu
    – JoelFan
    Commented Dec 21, 2010 at 21:29
  • 1
    @JoelFan: nvi is a pretty basic vi, it aims for compatibility with the original implementation and nothing more. If you're only interested in desktop installations or servers where you can install programs easily, you can assume vim is available. Familiarity with lesser vi implementations is only useful on locked-down servers and embedded devices. Commented Dec 21, 2010 at 21:42
  • 1
    I use "vi" mostly for servers, where I can install things, yes
    – JoelFan
    Commented Dec 21, 2010 at 22:18

'] or '> could also be useful here.

From :h motion.txt:

'] `] To the last character of the previously changed or yanked text.

'> `> To the last line or character of the last selected Visual area in the current buffer. For block mode it may also be the first character of the last line (to be able to define the block). Note that 'selection' applies, the position may be just after the Visual area.


I'm pretty sure this is by design. If you paste using "p" (lower case P), it's supposed to paste after the current position or line. However, if you paste using "P" (capital P), then it pastes before the current position or line. If your desired behavior is to have the cursor be at the end of your newly pasted text, try getting in the habit of using "P" instead of "p".

I bet if you dug deep enough, you could find a vim recipe to put in your .vimrc that would always move the cursor to the end of your paste, even if you use "p".

  • 2
    P leaves the cursor at the beginning of the pasted text in vi (at least in nvi and per POSIX). Commented Dec 21, 2010 at 19:42
  • 2
    p and P affect the position of the insert with respect to the surrounding text. they don't affect the position of the cursor itself which is always at the same position relative to the inserted text.
    – eMBee
    Commented Jan 7, 2019 at 14:41

according to https://unix.stackexchange.com/a/5060/457327 and my habit, I map:

    nnoremap p P
    " nnoremap p <left>P  (does not work)

    " p: paragraph  
        nnoremap vP Vip
        nnoremap <leader>v Vip

    nnoremap P v$<left>P
        " like  Y D C

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .