Something that I want to do from time to time is paste the output of a vim command into the buffer. E.g. when I'm editing my vimrc, it'd be nice to be able to fiddle with statusline
and then be able to just do something akin to
"=set statusline?<Enter>p
Problem is, that yields
E121: Undefined variable: set
E15: Invalid expression: set statusline?
Press ENTER or type command to continue
I figure that this is possible, and that I just don't know enough about the builtin functions and how to use them (I see expand
used here and there, but have never successfully made it work for me in any context), even though I (think that I) have a pretty solid understanding of normal mode.
Note that this specific example is a little contrived, but I can't think of a better one right now. For the specific use case above, I could just ":p
to get the whole set
command that I used during experimentation and then edit to suit, but fairly regularly I run into other cases where I want vim to tell me something and then I want to paste that output somewhere so that I can continue to look at it while continuing with my work.
Calling A Function Vim has a :call command to call a function. The call command does not output the return value. Let's call it with echo . To clear any confusion, you have just used two different call commands: the :call command-line command and the call() function.
You can paste an option setting:
"=&statusline<Enter>p
I don't know of any way to put the output of an arbitrary command in the buffer, however.
The values of settings are stored in variables that are prepended with an &
symbol. So the value that statusline
is set to can be accessed by referencing &statusline
. To insert into a document one way is to use the "expression" register, <ctrl-R>=
. To use it enter insert mode and press <ctrl-R>
and then =
. You will see an equals sign in the command line, where you can enter: &statusline
and then press enter
. This will insert the value into the buffer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With