I guess it is better to explain with an example, so here it is:
My useful line.
Some useless line.
Some other useless line.
Another useful line - oh I want this!
This is useful, I want this too!
In this example, I am searching for the string "useful". So, I want to copy lines 1, 4 and 5 to clipboard. How can I do this with vim?
First clear register a
(you can use any letter a-z) for using.
:let @a=''
Then run the magic.
:g/useful/yank A
It will search for lines matching pattern "useful" and then run command :yank A
to them. Capital A will append to the register a
.
If your vim is configured with global Windows/X clipboards, you can run
:let @+=@a
to copy the register a
's content to the clipboard.
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