Copy from one register to another

VimVim Registers

Vim Problem Overview


How to copy the contents of one register to another without pasting on clipboard? I'd yanked one text and it got yanked in the default " register. Now I want to copy another text without deleting/overwriting " register. So I want to move the contents of " register to say some a or b register so that I can copy the new text inside ". How to do this?

Vim Solutions


Solution 1 - Vim

To copy or swap values between registers you can use the :let command, for example to copy the contents of the b register to a:

:let @a=@b

Or copy the contents of the " register to a:

:let @a=@"

Check this Vim Tip for some good key mapping suggestions:

Solution 2 - Vim

You can do something like this:

let @a = getreg('"')

That'll copy the " register to the a register.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionbluegeneticView Question on Stackoverflow
Solution 1 - VimChristian C. SalvadóView Answer on Stackoverflow
Solution 2 - VimderobertView Answer on Stackoverflow