Reputation: 3248
Many times I find that I will will want to yank the content between quotes and paste them inside another set up of quotes. For example, take this code for instance.
var foo = 'bar',
baz = 'buz';
I would normally do a yi'
inside of 'bar'
to yank the word bar.
How do I replace buz with my yank? I know one option is to do a di'"0P
, I just wonder if there is an easier solution I'm overlooking.
Upvotes: 11
Views: 3906
Reputation: 13
also note after you replace the content in visual mode,the content being replaced will now in you register. command :reg will show it.
In your example, command p
will paste the buz
in the editor.
Upvotes: 0
Reputation: 172510
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.
Upvotes: 2
Reputation: 258138
With your cursor anywhere on the word buz
, vi'p
to visually select inside the quotes and then put the contents of the most recent yank.
Upvotes: 29