I want to search within a function, and copy all lines which are calling a different function within that scope, to a different file. I know I can limit the scope of the search by visual selection, and search is easy - but I'm not getting a convenient way of copying all search results to any buffer (which I can then paste to another file for my analysis)... Can someone point to the solution (I'm almost sure it would be pretty easy, but for some reason, its not obvious to me !!) ?
You can use:
:let @a='' " clear register a. A faster alternative would be “qaq” in normal mode (thanks ZyX)
:g/pattern/y A " yank all lines with pattern into register a, but in append mode (hence a capital letter)
:buffer other_file.txt
"ap
Maybe this answer about registers can be of some help for you.
An alternative if you want to APPEND to your other buffer:
:redir >> other_file.txt
:g/pattern/# "alternative: :g/pattern/print or :g/pattern/number.
:redir END
References : :help :g
, :help :#
, :help :redir
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With