把Vim的命令输出重定向

事情可以这样举例吧. 

1.我可知在gvim是不是支持cscope, 
2.的运行gvim后, 
在命令模式输入 
:version 
出来一大堆feature,, 
我想知道里面有没有cscope 
用鼠标也copy不下来,,, 
也不能把这个作为输出重定向..... 
我主要不想一个一个看,把其保存到文本中,再搜 
cscope那样会好一点, 

可是...我不知道怎样保存 
:version后的输出,, 

各位大大请指教 ...


结果,热心的大牛们提出下面两种方法


一,转自

http://vim.wikia.com/wiki/Capture_ex_command_output


Tip 95 Printable Monobook Previous Next

created 2001 · complexity intermediate · version 7.0


Ever want to capture the output of an ex command like :set all into a Vim text buffer for easy viewing? This is actually a very easy thing to accomplish!

You can use the :redir command to redirect the output of an ex command to a register and then paste the contents of the register into a Vim buffer.

For example:

:redir @a
:set all
:redir END

Now, register 'a' will have the output of the "set all" ex command. You can paste this into a Vim buffer, using "ap.

You can also write a Vim function to do the above. Since you probably don't want your command output to mess up your carefully constructed window layout, this function will pipe the output of a command into a new tab, allowing you to simply close the tab when done. If you don't like using tab pages, or you don't have tab support because you didn't compile with it or your Vim version is less than 7.0, you could modify this function to use a new split window instead:

function! TabMessage(cmd)
  redir => message
  silent execute a:cmd
  redir END
  tabnew
  silent put=message
  set nomodified
endfunction
command! -nargs=+ -complete=command TabMessage call TabMessage(<q-args>)

Example usage:

:TabMessage highlight

Note that :redir can use a variable instead of a register, as shown above.

ReferencesEdit

Related scriptsEdit

CommentsEdit

This may be obvious to experts, but it took me a very long time to figure it out, because Google searches on terms like 'pipe', 'buffer', 'shell', etc never brought it to my attention. However, you can pipe the contents of the file currently being edited (the current buffer) to a shell command, and replace the current file/buffer with the _output_ of that command, using this:

:%! [cmd]

ie, if you didn't know the :retab command (as for a long time I didn't), you could expand tabs using basic unix commands like ":%! expand -t 4". Wish I'd known this a long time ago, so I'm posting it here in the hopes that others might find it :-)


The answer is (for example):

:read !ls ~

and :help :read for more information.


另一种是用vim 命令的在shell上的重定向输出.............

vim --version > /path-to/filename
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值