Vim: `s/foo/bar` Replaces All Instances Of "foo" In The File
This one has been nagging me for a bit. In vim, replacing with s/foo/bar
will typically only change the first instance of foo on the same line as the cursor. s/foo/bar/g
would do the same for all instances of foo on that line. If you had a selection, each command would do the same thing but for the whole selection rather than a single line, e.g. with the following text all selected:
foo foo foo
foo foo foo
foo foo foo
s/foo/bar
would output:
bar foo foo
bar foo foo
bar foo foo
and s/foo/bar/g
would replace all instances of foo in the selection with bar. This behaviour is useful for quick renames of local variables, replacement of misordered words, etc.