Re: global and yank
- * * Scott LaBounty <slabounty@...> [2002-11-27 19:09:44 +0100]:
> > let @a=""* Tim Chase <gumnos@...> [2002-11-27 19:22:38 +0100]:
> > g/pattern/normal "AY
> let @a=""Here's another variation. Of course, the solutions above will
> g/pattern/y A
do quite nicely in most cases, especially when typed in
manually by the user. But if this is to be used in a script or
a mapping, the following may be a little more robust:
:let @a = ""
:g/pattern/sil y A
:let @a = substitute(@a, "^\n", "", "")
The first and last commands (mark ' and norm ``) are used to
keep the cursor at the same position after the commands have
been executed (otherwise the g// command will move it to the
last line matching the pattern).
The sil (silent) command is used to avoid the "-- More --" and
"Hit ENTER or type command to continue" messages. (Well, these
are actually displayed because I've set the 'report' option to
0, the default is 2).
The substitute() is necessary to get rid of the newline which
is inserted at the start of the a register when the first
matching line is append-yanked.
By the way, does anyone know of a way to avoid this leading
newline when appending? Is this a bug in vim? When appending
a line to a register which only contains an empty string, I
don't think it's expected behaviour to first insert a newline.
Another strange thing is that if the register hasn't been used
before the line-append-yanking (that is, if it's not listed by
the ;reg command), the newline is *not* inserted at the start.
So if it was possible to set a register "unused", it could be
solved that way. I've tried
but that gives the error message
E108: No such variable: "@a"
And interestingly the command
makes vim freeze completely, and I have to kill it.
Erik Warendorph <erik.warendorph@...>