How can replace string in quotes with string from buffer?
I'm doing the following to copy some text inside quotes and paste it in a different place (inside quotes as well):
di"
go-to-buffer-for-copy
copy-string (ex. yi")
then-go-to-prev-buffer
paste-to-string (p)
But I want to do it in a simpler way, like this:
yi"
go-to-buffer-for-paste
replace-inner-quotes-to-y开发者_如何转开发anked-text
For "replace-inner-quotes-to-yanked-text" you can use vi"p
.
(pulling my comment into its own answer)
Assuming you use vim
with system clipboard, you could do the following:
"+yi"
to copy the text inside quotes to your system clipboard- position your cursor inside the quotes where you want to put that text
ci"<Ctrl-V><Esc>
replaces what's inside the quotes with the content of your clipboard
One benefit is that if you want to put the original text in multiple places, you can place your cursor in the next position and press .
.
vi"p
, proposed by Randy Morris, works but it replaces the content of your default register and the selection won't be captured in the "do again" command, only the paste.
You could still use the "0
register to access your original text but I haven't found a command that would change inside the quotes and paste in a way that redo maintains.
This technique enables you to stay out of insert mode and doesn't require mapping the unnamed clipboard to the system clipboard:
yi"
(yank inside the quotes?'
followed by first few letters of current contents of target quotes (search back)p
(paste)dt"
(delete the pre-existing content that was in the quotes
精彩评论