In particular, I'd like to append to the unnamed register with the
There's no shortcut to append only to the default register (the way you can append to a letter register by using the uppercase register name.)
In order to append only to the default register, you'd have to use a full
let @" .= ... expression, such as:
:g/pattern/let @" .= getline('.')."\n"
But that's quite unsatisfying. It's much better to use a letter register instead, and then use the uppercase version of the register to append to it.
Writing to a letter register will also write to the unnamed register (thanks @Mass for pointing that out!). From [
Vim fills this register with text deleted with the
xcommands or copied with the yank
ycommand, regardless of whether or not a specific register was used (e.g.
"xdd). This is like the unnamed register is pointing to the last used register. Thus when appending using an uppercase register name, the unnamed register contains the same text as the named register.
So we can just use a named register as a "proxy" to the unnamed register. We can initialize it with the initial contents of the unnamed register, then append to it, which will get the unnamed register to include the appends:
:call setreg('x', @", getregtype('"')) :g/pattern/y X
While you'll be primarily appending to register
"x, the unnamed register will also get the same contents, mirroring the named register you last appended to.