Reputation: 317
Something that I find myself doing often is yanking the text between two parenthesis and pasting that over another pair of parenthesis. For example:
foo(int a, int b, int c)
bar(int d, int e)
becomes
foo(int a, int b, int c)
bar(int a, int b, int c)
Is there a quick way in Vim to yank the text from foo and paste it over the text in bar?
Upvotes: 7
Views: 4780
Reputation: 11
Use this to go to last parenthesis shift + 5
.
Press 5 twice for the first parentheses.
Upvotes: 1
Reputation: 11
I use vim-scripts/ReplaceWithRegister.
Copy as usual with
yi(
Paste with gri(
Upvotes: 1
Reputation: 3917
One way would be yi)
inside foo's arguments and "_di)P
within bar's arguments.
yi)
yanks the text inside the parentheses
"_di)P
uses the null register to delete the text inside the parentheses and pastes the text, vi)p
also works and avoids the null register
The only thing changing is the function name though, so you could also just yank the line and use cw
(change word) to change foo to bar.
Upvotes: 12
Reputation: 196876
Yank the content of the first pair of parentheses:
yib
Visually select the content of the second pair of parentheses and put:
vibp
Upvotes: 16
Reputation: 20909
Cursor over the first paren of foo
, then use y%
to yank all the text until the matching paren. (You can also use v%y
if you prefer to visually see the text you're yanking.)
Then cursor over the first paren of bar
, then use v%p
. It selects the text up until the matching paren then pastes over it.
Upvotes: 4