cursor position after pasting in vi / vim
Clash Royale CLAN TAG#URR8PPP
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?
vim vi
add a comment |
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?
vim vi
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
add a comment |
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?
vim vi
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?
vim vi
vim vi
asked Dec 21 '10 at 18:08
JoelFanJoelFan
540713
540713
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
add a comment |
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
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
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
sorry, at least
– Alexey
Dec 10 '13 at 11:45
add a comment |
2 Answers
2
active
oldest
votes
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
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
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.
– Gilles
Dec 21 '10 at 21:42
1
I use "vi" mostly for servers, where I can install things, yes
– JoelFan
Dec 21 '10 at 22:18
add a comment |
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).
– Gilles
Dec 21 '10 at 19:42
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
Jan 7 at 14:41
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f5056%2fcursor-position-after-pasting-in-vi-vim%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
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
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
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.
– Gilles
Dec 21 '10 at 21:42
1
I use "vi" mostly for servers, where I can install things, yes
– JoelFan
Dec 21 '10 at 22:18
add a comment |
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
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
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.
– Gilles
Dec 21 '10 at 21:42
1
I use "vi" mostly for servers, where I can install things, yes
– JoelFan
Dec 21 '10 at 22:18
add a comment |
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.
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.
edited Apr 20 '18 at 18:29
Community♦
1
1
answered Dec 21 '10 at 19:41
GillesGilles
532k12810681594
532k12810681594
1
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
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.
– Gilles
Dec 21 '10 at 21:42
1
I use "vi" mostly for servers, where I can install things, yes
– JoelFan
Dec 21 '10 at 22:18
add a comment |
1
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
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.
– Gilles
Dec 21 '10 at 21:42
1
I use "vi" mostly for servers, where I can install things, yes
– JoelFan
Dec 21 '10 at 22:18
1
1
I think "vi" is usually really "vim" in most distros, right?
– JoelFan
Dec 21 '10 at 20:06
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
@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
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
1
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.
– Gilles
Dec 21 '10 at 21:42
@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
1
1
I use "vi" mostly for servers, where I can install things, yes
– JoelFan
Dec 21 '10 at 22:18
I use "vi" mostly for servers, where I can install things, yes
– JoelFan
Dec 21 '10 at 22:18
add a comment |
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).
– Gilles
Dec 21 '10 at 19:42
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
Jan 7 at 14:41
add a comment |
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).
– Gilles
Dec 21 '10 at 19:42
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
Jan 7 at 14:41
add a comment |
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".
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".
answered Dec 21 '10 at 19:37
SethGSethG
29424
29424
2
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
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
Jan 7 at 14:41
add a comment |
2
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
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
Jan 7 at 14:41
2
2
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
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
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
Jan 7 at 14:41
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
Jan 7 at 14:41
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f5056%2fcursor-position-after-pasting-in-vi-vim%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
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