开发者

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

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 ju开发者_开发问答st ":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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜