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?
Asked
Active
Viewed 1.4k times
106
Mike Bailey
- 12,021
- 13
- 64
- 120
bluegenetic
- 1,237
- 4
- 11
- 13
2 Answers
136
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:
Christian C. Salvadó
- 769,263
- 179
- 909
- 832
-
1Somehow I cannot get this to work. I have a pretty minimal vim on this mcahine. Here are some of my settings. VIM - Vi IMproved 7.0 (2006 May 7, compiled Mar 5 2011 21:36:07) Included patches: 1, 3-4, 7-9, 11, 13-17, 19-26, 29-31, 34-44, 47, 50-56, 58-64, 66-73, 75, 77-92, 94-107, 109, 202, 34-237 Compiled by
Tiny version without GUI. – Paul Apr 24 '14 at 19:01 -
1@Paul, as far I remember the *small* and *tiny* feature sets of Vim do not support the `:let` command. – Christian C. Salvadó Apr 24 '14 at 21:57
-
Can you explain what `@` does? – Gqqnbig Mar 03 '18 at 19:51
-
`@` is the way of working with registers as variables. See `:help let-register` for details. You can basically just think of it as `@a` being the variable where register `a` is stored. – cincodenada Mar 22 '18 at 21:21
8
You can do something like this:
let @a = getreg('"')
That'll copy the " register to the a register.
derobert
- 47,899
- 11
- 91
- 122