g flag in :s useless in vim

Some time back there was a post on vim_use list about the “/g” flag for the search and replace functionality of the vim. And the response of “Tim Chase” on the same was very elaborate and interesting. I always knew that “/g” is only for replacing multiple occurrences on the same line, but here are few things that I did not know.

   :0/this/s//that

This one will only replace the first occurrence of this in the whole file.

   :-/this/s//that

This one will replace the first occurrence of this in the file from current cursor position including the current line.

And finally here is the link to the post.

Enhanced by Zemanta