How do I substitute from a list of strings in VIM?

后端 未结 5 1621
感情败类
感情败类 2020-12-21 00:26

I am a vim user, and I want to be able to loop over a range of substrings when I am substituting. How can I use some vim magic to go from a set of lines like this:



        
5条回答
  •  我在风中等你
    2020-12-21 00:50

    It's probably going to be much easier to record a macro that can replace the first two, and then use :s for the rest.

    The macro might look like /foo^Mcwbar^[. If you're not familiar with macro mode, just hit q, a (the register to store it in) and then the keystrokes /foo cwbar .

    Now once you've got that macro, do 2@a to replace the first two occurrences in the current buffer and use :s normally to replace the rest.

提交回复
热议问题