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

后端 未结 5 1620
感情败类
感情败类 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 01:05

    This is how I'd attempt that macro.

    qa          Records macro in buffer a
    /foo    Search for the next instance of 'foo'
    3s          Change the next three characters
    bar         To the word bar
           Back to command mode.
    n           Get the next instance of foo
    .           Repeat last command
    n           Get the next instance of foo
    3s          Change next three letters
    baz         To the word bar
           Back to command mode.
    .           Repeat last command
    q           Stop recording.
    1000@a      Do a many times.
    

    Any advice on how to do it better is welcome.

    thanks, Martin.

提交回复
热议问题