Thursday, May 28, 2015

Re: Replicate TextPad feature (copy marked lines)

On 2015-05-28 13:54, skeept wrote:
> He would use find with a string or regular expression. Then he can
> mark all matching lines. He can repeat the process with several
> strings.
>
> After that he would copy all the marked lines and paste to another
> window.

The common way to do this is to pull the matches into a register:

:let @a='' | g/pattern/y A

This will gather all the lines matching "pattern" into the "a"
register which you can paste within vim

:new
"ap

or assign to the system clipboard:

:let @+=@a

If you have multiple search terms, you can (as you mention) build the
expression out of the gate (or incrementally thanks to Vim's
command-line history):

:let @a='' | g/pattern1\|pattern2\|pattern3/y A

That is what I usually do when I want this functionality.

If you want to build it incrementally by searching instead, you can
use the search register, recall the previous search, and append your
additional term

/pattern1<cr>
/<up>\|pattern2<cr>
[repeat until you have all the terms you want]
:let @a='' | g//y A

There might be some plugins that simplify these actions, but under
the hood they would likely do the same thing as this.

-tim


--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: