Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?
share|improve this question

1 Answer 1

up vote 4 down vote accepted
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).

share|improve this answer
1  
The z#.2 doesn't work because it addresses 1/2 above / below, and that seems to be rounded down to 1. –  Ingo Karkat Feb 11 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 at 16:55

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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