Can someone explain why range search :[range]/pattern/action
does not work the same way as :[range]g/pattern/action
?
Also :'a,'b/pattern/action
gives a warning that the range is 'backward', even though 'a
is less than 'b
Vi and Vim Stack Exchange is a question and answer site for people using the vi and Vim families of text editors. It only takes a minute to sign up.
Sign up to join this communityIn :[range]/pattern/action
, the /pattern/
part is actually part of the range.
See :help cmdline-ranges
, which includes a full explanation of ranges, including this detail:
The
/
and?
may be preceded with another address. The search starts from there.
So if you have 5/foo/
it means the first line matching "foo" after line 5, or 'b/bar/
means the first line matching "bar" after mark 'b
.
So :'a,'b/pattern/p
means print lines from mark 'a
to the first line matching /pattern/
after mark 'b
.
Note how this is very different from :'a,'bg/pattern/p
, where the /pattern/
is not part of the range, but instead it's an argument to the :g
command. The :'a,'bg/pattern/p
command will print only lines matching /pattern/
inside the range going from line where mark 'a
is, to the line where mark 'b
is (inclusive.)
"Slash" is not a command for command-line mode. It's a line address. Hence That's why.:'a,'b/pattern/
is the same as :'a,/pattern/
'b/pattern/
in a range means the first line matching /pattern/
after the 'b
mark.