Tuesday, February 17, 2015

gvim - Vim - how to substitute a word in-place?


I would like to substitute a word in-place. For example, after yanking some word by pressing yw and then setting a cursor on some other word, I would like to press something so that substitution will happen. (e.g. SOME_KEYw where w is really w and SOME_KEY is some key). I would not like to switch into Insert Mode.


I am not interested in the :%s/oldword/newword/gc solution. I need interactive in-place substitution!


Answer



What you are looking for is described in Vim Tip 605.


If you yank the first word with yiw, you can then replace another word with the first one by typing viwp.


If you leave out the i, yw will also yank the whitespace after your word and when pasting this you get too much spaces. Therefore, use i to select the inner word.


No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...