On 2020-07-24 05:36, Manas wrote:
> On Thu, Jul 23, 2020 at 06:40:17PM -0500, Tim Chase wrote:
> > :let @a='' | g/^-/y A
> >
> It worked like a charm. Apparently, the right command was `:g/^-/y
> A` instead of `:g/^-/normal yy`. Although I am not able understand
> the use of `A` after `y`. Can you please explain that?
The ex "y" command yanks and can take an optional register to yank
to. By default, your
:g/^-/normal yy
(using the normal-mode) would be the same as ex-mode "y" command:
:g/^-/y
which yanks, overwriting the default " register.
If you specify a register, vi/vim will yank into that register
instead. In normal mode, you'd prefix your command with the
register-name:
"ayy
to yank the current line into register "a".
The trick is that *uppercase* registers write to the same register as
their lowercase variants, but they *append* instead of *overwrite*.
:help quote_alpha
So by using
:g/^-/y A
(or as a jump to normal mode
:g/^-/normal "Ayy
would do the same thing) each line matching your pattern gets yanked
*and appended* to register "a", gathering them all up so you can then
use the "a" register either to paste or transfer the results to the
system clipboard (the "+" register) via a `:let` command
:let @+=@a
Hopefully that makes more sense of it?
-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.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20200723201823.0b889ff2%40bigbox.attlocal.net.
Thursday, July 23, 2020
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment