How is it possible to :hardcopy all the lines – and only those – resulting from a pattern search ?
I tried :
:g/pattern/ha
but it did not work (3 occurrences gave 3 hardcopies of the entire file…)
Thanks in advance
PS : I should have added that I wish to print the line numbers AND keep the original line numbers (e.g, pattern in lines 3, 7, 8, print 3, 7, 8 and not 1, 2, 3)
Try deleting those lines which do not match.
To capture the output of
:g//nu, look into the:redircommand, according to Capture ex command output on the Vim wiki. They give this example:and then paste the output into a new buffer, which you can print.