Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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


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


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

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


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}.
                            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
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 '14 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 '14 at 16:55

Your Answer


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.