vmware-archive / vim-config

This is the Vim configuration we use on pairing machines at Neo, as well as many Neons' personal machines. It's pretty okay.
BSD 2-Clause "Simplified" License
64 stars 41 forks source link

global substitute bug #59

Closed sushengloong closed 9 years ago

sushengloong commented 9 years ago

My environment

  1. OS version: OSX Yosemite
  2. Vim version: VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Feb 14 2015 17:25:26) MacOS X (unix) version
  3. vim-config version: a961098 (latest master revision as of now)

Steps to reproduce:

  1. Launch vim
  2. Insert text foo foo
  3. :%s/foo/bar/g
  4. The text becomes bar foo - only the first foo is substituted.

However, when I launched vim -u NONE and did the steps above, both foo's were replaced with bar successfully. Appreciate if anyone could help verify and fix this. Thanks.

alanyjw commented 9 years ago

@sushengloong This is caused by set gdefault in general_config.vim. If you were to do :%s/foo/bar instead, the correct behaviour is expected. Putting an additional g flag with gdefault turned on, will cause it to substitute only one.

From :help gdefault:

When on, the ":substitute" flag 'g' is default on. This means that all matches in a line are substituted instead of one. When a 'g' flag is given to a ":substitute" command, this will toggle the substitution of all or one match.

Hope this helps!

sushengloong commented 9 years ago

Sorry, I didn't know about gdefault. Thanks @alanyjw for explaining.