I’m using the multiselect plugin. I have selected multiple contiguous blocks of code and want to yank all of them into one register. For example, from

-- selected A --
—— unselected ——
-- selected B --

I want to have

-- selected A --
-- selected B --

in one register. Executing MSExecCmd yank yanks the contiguous blocks into separate registers.

So how can I yank them into one?

  • 3
    In which registers does the plugin store your blocks of code ? I don't know if it solves your problem, but let's say the 3 registers a, b and c contain data that you want to merge into the register d. To do so, you can type let @d=@a.@b.@c. The dot is an operator that concatenates strings. – saginaw Nov 13 '15 at 14:00
  • saginaw: Didn’t know that, nice. Thanks! But it doesn’t really solve my problem because I have like 20 blocks to yank. – k.stm Nov 13 '15 at 16:49
  • 2
    I don't know how your plugin works, but here's how I would do it without the plugin. Add a mapping in my ~/.vimrc that maps <leader>c to "Ay in visual mode, which gives : vnoremap <leader>c "Ay. Then, in vim clear the register a : let @a="". Then, visually select first block of code and type <leader>c, go to second block of code, visually select it and type <leader>c, etc. When I'm finished and I want to paste the concatenated blocks, I would type in normal mode "ap. – saginaw Nov 14 '15 at 11:17
  • 1
    Just to explain, when you use "ay on a visually selected text, the text overwrites the content of the register a, but when you use the capital letter instead of the lower one, it appends to the register instead of overwriting it. – saginaw Nov 14 '15 at 11:18
  • @saginaw Thanks. You could make this into an answer. (I haven’t tried it yet, but I understand that it will work.) – k.stm Nov 14 '15 at 12:12

What happens if you run:

:let @a=""
:MSExecNormalCmd "Ay

after you have your blocks visually selected?

... the idea (even if the above doesn't work) is still to yank-append each visually selected block to the same register. But, since you use a specific plugin, you are the one who should know how to do it (i.e. reading the plugin's help).

| improve this answer | |
  • 1
    Yes, this works. Thanks! (About that I am the one who should know how to do it: Maybe, but in this case, I think, it’s less about the plugin and more about the logic of vim itself.) – k.stm Nov 14 '15 at 12:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.