Question

Instead of typing:

:%s/a/b/g

I accidentally typed:

:$s/a/b/g

Then Vim highlights all "a".

I then tried:

:%s/a/

It also highlights all "a"s, but if I run the command again, it says "a" is not found.

So what is the proper use of :$s?

Was it helpful?

Solution

$ in this case refers to a range. The command :$s/a/b/g performs the replacement only on the last line of the file, however matches (as) are highlighted everywhere, in both cases.

For more information, see :h range and :h :s.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top