How to replace all word containing a pattern in vim?

This question already has an answer here:

  • Regular expression to match a line that doesn't contain a word? 25 answers

  • You can use the substitution command like this:

    :%s/before/after/g
    

    where

  • %s is the substitution
  • before is the string to match
  • after is the replacement
  • g is the global flag (to replace all occurrences)
  • If you are matching substrings, you can use

    :%s/<w*substrw*>/newword/g
    

    where

  • < matches the word boundary
  • w* matches a word character (0 or more)
  • substr is your substring
  • > matches the word boundary end
  • newword is the new word to replace
  • g is the global replace
  • 链接地址: http://www.djcxy.com/p/13388.html

    上一篇: 正则表达式以避免给定的一组子字符串

    下一篇: 如何替换vim中包含模式的所有单词?