In Vim how can I search and replace every other match?

后端 未结 7 1267
Happy的楠姐
Happy的楠姐 2020-12-23 23:41

Say I have the following file


    
    


    

        
相关标签:
7条回答
  • 2020-12-24 00:18

    I'd do it with a macro:

    qv            start recording in register v
    /"bar"/e<cr>  search for "bar" and position the cursor at the end of the match
    i1<esc>       insert 1 before the cursor and go back to normal mode
    n             jump to next match
    q             stop recording
    

    After that, do {count}@v.

    0 讨论(0)
提交回复
热议问题