VIM: Finding and replacing first N occurrences of a word

前端 未结 4 1495
一向
一向 2020-12-28 08:39

I am editing a file and i want to change only a specific word with another word, but only for first N occurrences. I tried multiple commands

N :s/word/newword/

4条回答
  •  执念已碎
    2020-12-28 09:06

    I'm not sure about specifying the first N occurrences, but I often use this command:

    :%s/word/newword/gc
    

    Vim then asks for confirmation of each occurrence of word so you can selectively change some but not others.

提交回复
热议问题