4

I was looking for a way to show a bit of context around my searches when doing

g/mysearchtext/p

When I stumbled across this page Search-a-pattern-and-provide-a-context-few-lines-above-and-below where someone mentions the mysterious (to me) search flag 'z'. As in

g/cat/z#.3

My initial research suggests it some sort of 'total number of lines returned per result' but setting it to z#.2 only shows one line per search result. So I am confused and I'm having trouble finding the docs under :help pattern.

So here are my questions:

  • What does the z flag do?
  • How does #.3 modify it?
  • Where in the docs can I find this information?

1 Answer 1

5
g/cat/z#.3

Let's dissect this. :help :g tells you that the last thing is a command, not a flag (like those of :substitute):

:[range]g[lobal]/{pattern}/[cmd]

Let's try :help :z; voilà:

:{range}z[+-^.=]{count} Display several lines of text surrounding the line
                            specified with {range}, or around the current line
                            if there is no {range}.
:{range}z#[+-^.=]{count}
                            Like ":z", but number the lines.

So, you'll get a numbered (#) printing of 3 lines around (.) the current line (that matches cat).

2
  • 1
    The z#.2 doesn't work because it addresses 1/2 above / below, and that seems to be rounded down to 1. Feb 11, 2014 at 16:43
  • Bah! Good call I definitely spaced on looking through the docs there. I was doing :help z (no colon).
    – jmathew
    Feb 11, 2014 at 16:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .