Vim: copy, then paste more than once
Clash Royale CLAN TAG#URR8PPP
I use the highlight mode in vim to copy a few characters. I then want to paste more than once. My current technique does not work well.
Sample text: Linux Solaris Irix HP-UX
Suppose I want to copy the word Linux
, then paste over Solaris
and Irix
.
- Place cursor at
L
inLinux
- Command
v
(for visual hilite), thene
(for end-of-word), theny
(for yank/copy) - Now
Linux
is on my "vim clipboard" - Move cursor to
S
inSolaris
(first instance) - Command
v
(for visual hilite), thene
(for end-of-word), thenp
(for paste) - Text is now:
Linux Linux Irix HP-UX
, but nowSolaris
is on my "vim clipboard" - Move cursor to
I
inIrix
(second instance) - Command
v
(for visual hilite), thene
(for end-of-word), thenp
(for paste) - Text is now:
Linux Linux Solaris HP-UX
which is not what I expected.
I resort to using highlite/paste with the mouse (via X Terminal). Surely, I can do this better. How?
vim
add a comment |
I use the highlight mode in vim to copy a few characters. I then want to paste more than once. My current technique does not work well.
Sample text: Linux Solaris Irix HP-UX
Suppose I want to copy the word Linux
, then paste over Solaris
and Irix
.
- Place cursor at
L
inLinux
- Command
v
(for visual hilite), thene
(for end-of-word), theny
(for yank/copy) - Now
Linux
is on my "vim clipboard" - Move cursor to
S
inSolaris
(first instance) - Command
v
(for visual hilite), thene
(for end-of-word), thenp
(for paste) - Text is now:
Linux Linux Irix HP-UX
, but nowSolaris
is on my "vim clipboard" - Move cursor to
I
inIrix
(second instance) - Command
v
(for visual hilite), thene
(for end-of-word), thenp
(for paste) - Text is now:
Linux Linux Solaris HP-UX
which is not what I expected.
I resort to using highlite/paste with the mouse (via X Terminal). Surely, I can do this better. How?
vim
add a comment |
I use the highlight mode in vim to copy a few characters. I then want to paste more than once. My current technique does not work well.
Sample text: Linux Solaris Irix HP-UX
Suppose I want to copy the word Linux
, then paste over Solaris
and Irix
.
- Place cursor at
L
inLinux
- Command
v
(for visual hilite), thene
(for end-of-word), theny
(for yank/copy) - Now
Linux
is on my "vim clipboard" - Move cursor to
S
inSolaris
(first instance) - Command
v
(for visual hilite), thene
(for end-of-word), thenp
(for paste) - Text is now:
Linux Linux Irix HP-UX
, but nowSolaris
is on my "vim clipboard" - Move cursor to
I
inIrix
(second instance) - Command
v
(for visual hilite), thene
(for end-of-word), thenp
(for paste) - Text is now:
Linux Linux Solaris HP-UX
which is not what I expected.
I resort to using highlite/paste with the mouse (via X Terminal). Surely, I can do this better. How?
vim
I use the highlight mode in vim to copy a few characters. I then want to paste more than once. My current technique does not work well.
Sample text: Linux Solaris Irix HP-UX
Suppose I want to copy the word Linux
, then paste over Solaris
and Irix
.
- Place cursor at
L
inLinux
- Command
v
(for visual hilite), thene
(for end-of-word), theny
(for yank/copy) - Now
Linux
is on my "vim clipboard" - Move cursor to
S
inSolaris
(first instance) - Command
v
(for visual hilite), thene
(for end-of-word), thenp
(for paste) - Text is now:
Linux Linux Irix HP-UX
, but nowSolaris
is on my "vim clipboard" - Move cursor to
I
inIrix
(second instance) - Command
v
(for visual hilite), thene
(for end-of-word), thenp
(for paste) - Text is now:
Linux Linux Solaris HP-UX
which is not what I expected.
I resort to using highlite/paste with the mouse (via X Terminal). Surely, I can do this better. How?
vim
vim
edited May 2 '13 at 7:01
jasonwryan
49.8k14134188
49.8k14134188
asked May 2 '13 at 2:07
kevinarpekevinarpe
342411
342411
add a comment |
add a comment |
5 Answers
5
active
oldest
votes
I would do that in this way (really useful for many paste):
- Go somewhere into the word
Linux
, then "ayiw to copy the word
"a to select register «a»
y for copying
i to specify we are "in" (the word, the paragraph, ...)
w to choose the word
- Got to next word w (or somewhere into the word)
- Paste on time and save that as macro qbdiw"aPq
qb to start recording macro in register «b»
d for deleting
i to specify we are "in" (the word, the paragraph, ...)
w to choose the word
"a to select the register «a» (previously saved)
P to paste the word before the cursor
q to stop recording the macro
- Then to use the macro the first time, go to the next word w and press @b
- Finally, and it is where the advantage of this method can be seen, go the each word you want to replace and press @@
Hint: Replace the w by W in qbdiw"aPq to select word with punctuation, like HP-UX
Issue: When the word is the last in the line it will delete the space before the word.
add a comment |
Use registers and avoid visual mode.
Move to 'L' (type 0fL) |L|inux Solaris Irix HP-UX
"lye
'Linux' is now in the 'l' register.
Move to 'S' (type fS) Linux |S|olaris Irix HP-UX
"sde"lP Linux Linu|x| Irix HP-UX
'Solaris' is now in the 's' register.
Move to 'I' (type fI) Linux Linux |I|rix HP-UX
"ide"lP Linux Linux Linu|x| HP-UX
You could also just delete 'Solaris ' and 'Irix ' and paste 'Linux ' twice in their place.
0fLw2dwbyf<space>w2P
add a comment |
I need this so often, I wrote a plugin to simplify and allow maximum speed: ReplaceWithRegister.
This plugin offers a two-in-one gr
command that replaces text covered by a motion / text object, entire line(s) or the current selection with the contents of a register; the old text is deleted into the black-hole register, i.e. it's gone. It transparently handles many corner cases and allows for a quick repeat via the standard .
command. Should you not like it, its page has links to alternatives.
add a comment |
You might want to consider "0p
when pasting in visual mode.
Ref :help v_p
Move to L in Linux
ye # Yank to end of word.
w # Move to next word.
<C>ve # Highlight Solaris.
"0p # Paste Linux, Solaris ends up in unnamed register and Linux in 0
w # Move to next word.
<C>ve # Mark next word. (Or anywhere else)
"0p # Paste Linux.
Or in this exact example one could also:
Positioned on L
in Linux
yww<C>v2f 2p
# Or
yww<C>v2el2p
yw # Yank Linux
w # Move to S in Solaris
<C>v2el # Enter visual mode, highlight two * end, and l to consume space.
2p # Paste Linux twice.
'<C>v2f ' # Alternative to <C>v2el
Or"_deP
--"_
is the "black hole register", and acts like /dev/null.
– SilverWolf
Mar 13 '18 at 18:41
add a comment |
Luckily for you and me, this question has beesn asked and answered on StackOverFlow. You can alter the default behaviour of p to be more intuitive or handy for some, by adding the following to your vimrc
file:
xnoremap p pgvy
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%2f74385%2fvim-copy-then-paste-more-than-once%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
I would do that in this way (really useful for many paste):
- Go somewhere into the word
Linux
, then "ayiw to copy the word
"a to select register «a»
y for copying
i to specify we are "in" (the word, the paragraph, ...)
w to choose the word
- Got to next word w (or somewhere into the word)
- Paste on time and save that as macro qbdiw"aPq
qb to start recording macro in register «b»
d for deleting
i to specify we are "in" (the word, the paragraph, ...)
w to choose the word
"a to select the register «a» (previously saved)
P to paste the word before the cursor
q to stop recording the macro
- Then to use the macro the first time, go to the next word w and press @b
- Finally, and it is where the advantage of this method can be seen, go the each word you want to replace and press @@
Hint: Replace the w by W in qbdiw"aPq to select word with punctuation, like HP-UX
Issue: When the word is the last in the line it will delete the space before the word.
add a comment |
I would do that in this way (really useful for many paste):
- Go somewhere into the word
Linux
, then "ayiw to copy the word
"a to select register «a»
y for copying
i to specify we are "in" (the word, the paragraph, ...)
w to choose the word
- Got to next word w (or somewhere into the word)
- Paste on time and save that as macro qbdiw"aPq
qb to start recording macro in register «b»
d for deleting
i to specify we are "in" (the word, the paragraph, ...)
w to choose the word
"a to select the register «a» (previously saved)
P to paste the word before the cursor
q to stop recording the macro
- Then to use the macro the first time, go to the next word w and press @b
- Finally, and it is where the advantage of this method can be seen, go the each word you want to replace and press @@
Hint: Replace the w by W in qbdiw"aPq to select word with punctuation, like HP-UX
Issue: When the word is the last in the line it will delete the space before the word.
add a comment |
I would do that in this way (really useful for many paste):
- Go somewhere into the word
Linux
, then "ayiw to copy the word
"a to select register «a»
y for copying
i to specify we are "in" (the word, the paragraph, ...)
w to choose the word
- Got to next word w (or somewhere into the word)
- Paste on time and save that as macro qbdiw"aPq
qb to start recording macro in register «b»
d for deleting
i to specify we are "in" (the word, the paragraph, ...)
w to choose the word
"a to select the register «a» (previously saved)
P to paste the word before the cursor
q to stop recording the macro
- Then to use the macro the first time, go to the next word w and press @b
- Finally, and it is where the advantage of this method can be seen, go the each word you want to replace and press @@
Hint: Replace the w by W in qbdiw"aPq to select word with punctuation, like HP-UX
Issue: When the word is the last in the line it will delete the space before the word.
I would do that in this way (really useful for many paste):
- Go somewhere into the word
Linux
, then "ayiw to copy the word
"a to select register «a»
y for copying
i to specify we are "in" (the word, the paragraph, ...)
w to choose the word
- Got to next word w (or somewhere into the word)
- Paste on time and save that as macro qbdiw"aPq
qb to start recording macro in register «b»
d for deleting
i to specify we are "in" (the word, the paragraph, ...)
w to choose the word
"a to select the register «a» (previously saved)
P to paste the word before the cursor
q to stop recording the macro
- Then to use the macro the first time, go to the next word w and press @b
- Finally, and it is where the advantage of this method can be seen, go the each word you want to replace and press @@
Hint: Replace the w by W in qbdiw"aPq to select word with punctuation, like HP-UX
Issue: When the word is the last in the line it will delete the space before the word.
answered May 2 '13 at 6:44
StreakyCobraStreakyCobra
43645
43645
add a comment |
add a comment |
Use registers and avoid visual mode.
Move to 'L' (type 0fL) |L|inux Solaris Irix HP-UX
"lye
'Linux' is now in the 'l' register.
Move to 'S' (type fS) Linux |S|olaris Irix HP-UX
"sde"lP Linux Linu|x| Irix HP-UX
'Solaris' is now in the 's' register.
Move to 'I' (type fI) Linux Linux |I|rix HP-UX
"ide"lP Linux Linux Linu|x| HP-UX
You could also just delete 'Solaris ' and 'Irix ' and paste 'Linux ' twice in their place.
0fLw2dwbyf<space>w2P
add a comment |
Use registers and avoid visual mode.
Move to 'L' (type 0fL) |L|inux Solaris Irix HP-UX
"lye
'Linux' is now in the 'l' register.
Move to 'S' (type fS) Linux |S|olaris Irix HP-UX
"sde"lP Linux Linu|x| Irix HP-UX
'Solaris' is now in the 's' register.
Move to 'I' (type fI) Linux Linux |I|rix HP-UX
"ide"lP Linux Linux Linu|x| HP-UX
You could also just delete 'Solaris ' and 'Irix ' and paste 'Linux ' twice in their place.
0fLw2dwbyf<space>w2P
add a comment |
Use registers and avoid visual mode.
Move to 'L' (type 0fL) |L|inux Solaris Irix HP-UX
"lye
'Linux' is now in the 'l' register.
Move to 'S' (type fS) Linux |S|olaris Irix HP-UX
"sde"lP Linux Linu|x| Irix HP-UX
'Solaris' is now in the 's' register.
Move to 'I' (type fI) Linux Linux |I|rix HP-UX
"ide"lP Linux Linux Linu|x| HP-UX
You could also just delete 'Solaris ' and 'Irix ' and paste 'Linux ' twice in their place.
0fLw2dwbyf<space>w2P
Use registers and avoid visual mode.
Move to 'L' (type 0fL) |L|inux Solaris Irix HP-UX
"lye
'Linux' is now in the 'l' register.
Move to 'S' (type fS) Linux |S|olaris Irix HP-UX
"sde"lP Linux Linu|x| Irix HP-UX
'Solaris' is now in the 's' register.
Move to 'I' (type fI) Linux Linux |I|rix HP-UX
"ide"lP Linux Linux Linu|x| HP-UX
You could also just delete 'Solaris ' and 'Irix ' and paste 'Linux ' twice in their place.
0fLw2dwbyf<space>w2P
edited May 2 '13 at 2:25
answered May 2 '13 at 2:16
user26112
add a comment |
add a comment |
I need this so often, I wrote a plugin to simplify and allow maximum speed: ReplaceWithRegister.
This plugin offers a two-in-one gr
command that replaces text covered by a motion / text object, entire line(s) or the current selection with the contents of a register; the old text is deleted into the black-hole register, i.e. it's gone. It transparently handles many corner cases and allows for a quick repeat via the standard .
command. Should you not like it, its page has links to alternatives.
add a comment |
I need this so often, I wrote a plugin to simplify and allow maximum speed: ReplaceWithRegister.
This plugin offers a two-in-one gr
command that replaces text covered by a motion / text object, entire line(s) or the current selection with the contents of a register; the old text is deleted into the black-hole register, i.e. it's gone. It transparently handles many corner cases and allows for a quick repeat via the standard .
command. Should you not like it, its page has links to alternatives.
add a comment |
I need this so often, I wrote a plugin to simplify and allow maximum speed: ReplaceWithRegister.
This plugin offers a two-in-one gr
command that replaces text covered by a motion / text object, entire line(s) or the current selection with the contents of a register; the old text is deleted into the black-hole register, i.e. it's gone. It transparently handles many corner cases and allows for a quick repeat via the standard .
command. Should you not like it, its page has links to alternatives.
I need this so often, I wrote a plugin to simplify and allow maximum speed: ReplaceWithRegister.
This plugin offers a two-in-one gr
command that replaces text covered by a motion / text object, entire line(s) or the current selection with the contents of a register; the old text is deleted into the black-hole register, i.e. it's gone. It transparently handles many corner cases and allows for a quick repeat via the standard .
command. Should you not like it, its page has links to alternatives.
answered May 2 '13 at 7:01
Ingo KarkatIngo Karkat
8,66411932
8,66411932
add a comment |
add a comment |
You might want to consider "0p
when pasting in visual mode.
Ref :help v_p
Move to L in Linux
ye # Yank to end of word.
w # Move to next word.
<C>ve # Highlight Solaris.
"0p # Paste Linux, Solaris ends up in unnamed register and Linux in 0
w # Move to next word.
<C>ve # Mark next word. (Or anywhere else)
"0p # Paste Linux.
Or in this exact example one could also:
Positioned on L
in Linux
yww<C>v2f 2p
# Or
yww<C>v2el2p
yw # Yank Linux
w # Move to S in Solaris
<C>v2el # Enter visual mode, highlight two * end, and l to consume space.
2p # Paste Linux twice.
'<C>v2f ' # Alternative to <C>v2el
Or"_deP
--"_
is the "black hole register", and acts like /dev/null.
– SilverWolf
Mar 13 '18 at 18:41
add a comment |
You might want to consider "0p
when pasting in visual mode.
Ref :help v_p
Move to L in Linux
ye # Yank to end of word.
w # Move to next word.
<C>ve # Highlight Solaris.
"0p # Paste Linux, Solaris ends up in unnamed register and Linux in 0
w # Move to next word.
<C>ve # Mark next word. (Or anywhere else)
"0p # Paste Linux.
Or in this exact example one could also:
Positioned on L
in Linux
yww<C>v2f 2p
# Or
yww<C>v2el2p
yw # Yank Linux
w # Move to S in Solaris
<C>v2el # Enter visual mode, highlight two * end, and l to consume space.
2p # Paste Linux twice.
'<C>v2f ' # Alternative to <C>v2el
Or"_deP
--"_
is the "black hole register", and acts like /dev/null.
– SilverWolf
Mar 13 '18 at 18:41
add a comment |
You might want to consider "0p
when pasting in visual mode.
Ref :help v_p
Move to L in Linux
ye # Yank to end of word.
w # Move to next word.
<C>ve # Highlight Solaris.
"0p # Paste Linux, Solaris ends up in unnamed register and Linux in 0
w # Move to next word.
<C>ve # Mark next word. (Or anywhere else)
"0p # Paste Linux.
Or in this exact example one could also:
Positioned on L
in Linux
yww<C>v2f 2p
# Or
yww<C>v2el2p
yw # Yank Linux
w # Move to S in Solaris
<C>v2el # Enter visual mode, highlight two * end, and l to consume space.
2p # Paste Linux twice.
'<C>v2f ' # Alternative to <C>v2el
You might want to consider "0p
when pasting in visual mode.
Ref :help v_p
Move to L in Linux
ye # Yank to end of word.
w # Move to next word.
<C>ve # Highlight Solaris.
"0p # Paste Linux, Solaris ends up in unnamed register and Linux in 0
w # Move to next word.
<C>ve # Mark next word. (Or anywhere else)
"0p # Paste Linux.
Or in this exact example one could also:
Positioned on L
in Linux
yww<C>v2f 2p
# Or
yww<C>v2el2p
yw # Yank Linux
w # Move to S in Solaris
<C>v2el # Enter visual mode, highlight two * end, and l to consume space.
2p # Paste Linux twice.
'<C>v2f ' # Alternative to <C>v2el
edited May 2 '13 at 14:13
answered May 2 '13 at 2:43
RuniumRunium
18.4k43060
18.4k43060
Or"_deP
--"_
is the "black hole register", and acts like /dev/null.
– SilverWolf
Mar 13 '18 at 18:41
add a comment |
Or"_deP
--"_
is the "black hole register", and acts like /dev/null.
– SilverWolf
Mar 13 '18 at 18:41
Or
"_deP
-- "_
is the "black hole register", and acts like /dev/null.– SilverWolf
Mar 13 '18 at 18:41
Or
"_deP
-- "_
is the "black hole register", and acts like /dev/null.– SilverWolf
Mar 13 '18 at 18:41
add a comment |
Luckily for you and me, this question has beesn asked and answered on StackOverFlow. You can alter the default behaviour of p to be more intuitive or handy for some, by adding the following to your vimrc
file:
xnoremap p pgvy
add a comment |
Luckily for you and me, this question has beesn asked and answered on StackOverFlow. You can alter the default behaviour of p to be more intuitive or handy for some, by adding the following to your vimrc
file:
xnoremap p pgvy
add a comment |
Luckily for you and me, this question has beesn asked and answered on StackOverFlow. You can alter the default behaviour of p to be more intuitive or handy for some, by adding the following to your vimrc
file:
xnoremap p pgvy
Luckily for you and me, this question has beesn asked and answered on StackOverFlow. You can alter the default behaviour of p to be more intuitive or handy for some, by adding the following to your vimrc
file:
xnoremap p pgvy
answered Jan 18 at 8:31
simlevsimlev
6032314
6032314
add a comment |
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%2f74385%2fvim-copy-then-paste-more-than-once%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