1

When I press : from visual mode, the command line is pre-populated with :'<,'>. It seems to affect how my substitutions work.

What do the characters mean and why are they inserted?

How does :'<,'>s/foo/bar/g differ from :s/foo/bar/g?

1 Answer 1

3

The substitute command can accept a range prefix. Without it, like:

:s/foo/bar/g

Will just substitute on the current (cursor) line.

:%s/foo/bar/g

Will substitute on the whole file.

:5,10s/foo/bar/g

Will substitute on lines 5 through 10, inclusive.

When you visually highlight some text, there are two marks that are automatically updated, mark < denoting the beginning of the visual area and > the end. When you have something visually selected and press : Vim assumes you want to do whatever command you're about to type on the visual area, so it pre-populates the command line.

See :help cmdline-ranges for more information on ranges, and :help mark-motions for more information on the various marks that can be used.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.