vimconcatenationvim-registers

Combining registers in vim


Is it possible to combine registers in vim? For example, if I have registers "a, "b, "c, can I easily create register "d which is a concatenation of all three? That is, without pasting them all and then selecting the whole thing.


Solution

  • With the command :let @a = "something" you can assign to a register.

    With the command :let @A = "another thing" or :let @a .= "another thing" you can append to a register.

    Lets say your registers are filled as follows (inspected using the reg command)

    :reg a b c
    --- Registers ---
    "a Apple^J
    "b Pear^J
    "c Banana^J
    

    Then you can call

    :let @D = @a
    :let @D = @b
    :ley @D = @c
    

    or

    :let @d = @a . @b . @c
    

    And your register d looks like

    :reg d
    --- Registers ---
    "d Apple^JPear^JBanana