Is there some built in functionality in Vim to merge the contents of two registers into a single register by appending the two?
It is not exactly clear what you would like to happen when e.g. one register contains a linewise selection and the other one contains a block selection. But for the easy case, you can always do (as noted in a comment)
and have the concatenation of register a and b in register c. But note, this might have funny effects, if the registers contain blockwise selections (or one register is of a different type than the other).
Let's say you want to merge
call setreg('c', getreg('a').getreg('b'))
You can of course replace
c by whatever register you want.
For a bit more of details:
getreg('x') will return the content of the register
x as a string.
In vim you can concatenate two strings with
. like this:
let str1 = 'foo' let str2 = 'bar' let result = str1 . str2 " result is equal to 'foobar'
getreg('a').getreg('b') concatenate the content of registers
setreg() allows you set the content of a register.
See the doc for more details:
When registers only contain strings, we can do it with the old
:let @c = @a . @b
If you want to handle the registers as lists (one element per line), then you'll need to use the new functions described by @statox, but beware, lists are concatenated with
:call setreg('c', getreg('a', 1, 1) + getreg('b', 1, 1))
Additionally and as an alternative:
if you only want to append something onto an allready filled register,
you can use the "uppercase-version" of the register-name.
- you're marking a line of text with shift+v,
- you'r "yanking" that text into register @a with shift+", a, y
- next you're marking another line of text ...
- and this one, you're appending onto register @a with shift+", A, y
As result you have two lines of text in register @a.