Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
895 views
in Technique[技术] by (71.8m points)

vim - Pasting inside delimiters without using visual selection

In Vim, let's say I want to replace the contents of one String with the content of another.

Original input

var1 = "January"
var2 = "February"

Desired output

var1 = "January"
var2 = "January"

What I would usually do is:

  • Move cursor to line 1
  • y i " (yank inner quotes)
  • Move cursor to the destination quote in line 2
  • v i " p (visual select inner quotes, paste)

While this works well, I generally try to avoid visual mode when possible, so I am not completely satisfied with my step 4 (v i " p).

Is there any way to specify a "destination paste area" without using Visual mode? I suspect it might be something chained to g, but I can't think of anything.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

There are many ways of doing this however using visual mode is the easiest.

  • Use the black hole register to delete the content then paste. e.g. "_di"P
  • Do ci"<c-r>0. <c-r> inserts the contents of a register
  • Simply paste and then move over a character and delete the old text. e.g pldt"

However visual mode still has my vote. I find that the concerns most people have is that using visual mode + paste is that the default register is swap with the selected text and it doesn't repeat well. Good news everybody! The 0 register always stores the last yank. The bad news is visual mode still doesn't repeat well. Take a look at this vimcast episode, Pasting from Visual mode, for more information. It mentions a few plugin that help with this.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...