What causes substitution in Vim to only match one element per line?

后端 未结 1 1620
既然无缘
既然无缘 2021-01-05 06:19

I\'ve been making a lot of changes to my .vimrc lately, and somewhere along the line I\'ve introduced an undesirable feature. When performing a substitution com

相关标签:
1条回答
  • The substitute command accepts the switch g, for global, which causes the substitution to be made on all matches on the line:

    :s/regex/replacement/g
    

    The default is that only the first occurrence of the match is substituted, but there's a setting to switch the default to global: gdefault. So set gdefault in your vimrc if you want this as the default behavior. Try it out first in the current vim session with :set gdefault.

    Note that when you set gdefault, this not only makes g the default behavior, but it changes the usage of the g flag so that using /g at the end of a substitute will cause the substitution to be made only once.

    See: :help gdefault.

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