I've the following text copied to the "0
register
test
test
If I want to copy the content of the
"0
register to the"a
register I do:let @a=@0
Then, if I paste the content of
"a
register I obtaintest test
Now, to paste the content of the
"0
register to the"a
register I do:let @a="
and then
<C-r>0
, and the result is this:let @a="test^Mtest^M"
Then I paste the content of
"a
register ("ap
) and I obtaintest^Mtest^M
Why are the results not equal?
Specifically, why the newline characters are written literally and not interpreted in the second case?
From
:help c_ctrl-r
:--- EDIT ---
<C-r>0
inserts the content of"0
as if you typed it. Since"0
contains a<CR>
(two, actually, but the second is irrelevant):that
<CR>
would be typed just as you would have typed it, which would result in the command being executed before the typing is finished:which would throw
E114
because of the missing"
.The compromise, here, is to insert a literal
^M
instead of typing<CR>
to allow the command-line to be finished.You don't have that problem with
:let @a = @0
because there is no typing and no I/O involved: it's just values being passed around.