I set a variable b:aaa
which has the value that I can see via echo b:aaa
, how can I copy that to text? I know I can do it by
set @a = b:aaa
"ap
to get it. But can I copy it to the an open file directly?
To put the value of a variable into a buffer use the :put
command with the expression register, @=
:
put=b:aaa
You can use a range with :put
to put it at a specific location. Put below the 9th line:
9put=b:aaa
Note: use :put!
to put above the current line
For more help see:
:h :put
:h @=
:h :range
Registers works like variables, so you are almost done. I think this would work for you:
let @a = b:aaa
"ap
:put
solution Peter Rincker mentions is good
setreg()
better @ChristianBrabandt? I thought it just existed to support things like setreg(l:some_var, "val")
?
Commented
Apr 11, 2017 at 20:08
<c-r>=b:aaa
string()
would add safety.:put=b:aaa
getreg()
andsetreg()
functions for setting the register to a specific value. And also see:h let-option
for setting the option to a variable.