1

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

2 Answers 2

2

In :[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.)

1

"Slash" is not a command for command-line mode. It's a line address. Hence :'a,'b/pattern/ is the same as :'a,/pattern/ That's why.

1
  • 1
    They're not quite equivalent... Address 'b/pattern/ in a range means the first line matching /pattern/ after the 'b mark.
    – filbranden
    Sep 6, 2020 at 16:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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