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.
:v/pattern/d
:ha
To capture the output of :g//nu
, look into the :redir
command, according to Capture ex command output on the Vim wiki. They give this example:
:redir @a
:g//nu
:redir END
and then paste the output into a new buffer, which you can print.
精彩评论