开发者

Vim hardcopy of a search pattern

开发者 https://www.devze.com 2023-03-05 23:14 出处:网络
How is it possible to :hardcopy all the lines - and only those - resulting from a pattern search ? I tried :

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号