Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to paste the output of a vim command into the buffer?

Tags:

vim

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.

like image 676
dash-tom-bang Avatar asked Dec 15 '10 02:12

dash-tom-bang


People also ask

How do you call a function in Vim?

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.


2 Answers

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.

like image 195
Laurence Gonsalves Avatar answered Oct 02 '22 23:10

Laurence Gonsalves


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.

like image 20
Herbert Sitz Avatar answered Oct 02 '22 22:10

Herbert Sitz