VIM: Finding and replacing first N occurrences of a word

前端 未结 4 1498
一向
一向 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:17

    My PatternsOnText plugin provides (among many others) a command that takes answers in the form of either yyynyn or 1-5:

    :%SubstituteSelected/word/newword/g 1-5
    

提交回复
热议问题