Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question
    
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 Dec 10 '13 at 11:13
    
sorry, at least –  Alexey Dec 10 '13 at 11:45

2 Answers 2

up vote 4 down vote accepted

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.

share|improve this answer
    
I think "vi" is usually really "vim" in most distros, right? –  JoelFan Dec 21 '10 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. –  Gilles Dec 21 '10 at 20:18
    
Waht about "nvi"? I'm confused about all the different vi's. I am mostly insterested in debian and ubuntu –  JoelFan Dec 21 '10 at 21:29
    
@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. –  Gilles Dec 21 '10 at 21:42
    
I use "vi" mostly for servers, where I can install things, yes –  JoelFan Dec 21 '10 at 22:18

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".

share|improve this answer
1  
P leaves the cursor at the beginning of the pasted text in vi (at least in nvi and per POSIX). –  Gilles Dec 21 '10 at 19:42

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.