When I use the normal mode and output the search result using the following input,

/LOAD \d\{-}\_p\+\d\n

it includes the first line, enter image description here

However when I use the ex-command,

:g/LOAD \d\{-}\_p\+\d\n/z

The output does not show the first line (line #504 is missing).

enter image description here

My intention is to redirect the output of the ex-command to another file, using the :redir command. How to include the first line to the search output using the ex-command?

2 Answers 2


I think this is not caused by the :g command or the matching, but by the :z command. If you go to the LOAD line and do :z, the same thing happens.

Strange workaround: Do :g/pattern/-0z


What about :% g/\vLOAD\_p+/, this uses "magic" and makes the regex more readable. You can read about it in more detail in :h /magic

This also solves the disappearing first line.

Your Answer

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

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