在Vim中将缓冲区缓冲到外部命令 [英] Piping buffer to external command in Vim
问题描述
我是Vim的新手.我想将当前缓冲区的内容发送到外部命令的stdin(比如说mail).我的最终目的是设置快捷方式,以从当前Vim缓冲区快速发送电子邮件.我猜这应该是一件小事,但我找不到将Vim缓冲区发送到外部命令的方法.预先感谢.
I am kind of a Vim novice. I would like to send contents of the current buffer to stdin of external command (lets say mail). My final purpose is to set a shortcut to quickly send email from current Vim buffer. I am guessing this should be a trivial stuff, but I couldn't find a way to send Vim buffer to an external command. Thanks in advance.
推荐答案
您可以使用:w !cmd
将当前缓冲区写入外部命令的stdin.来自:help :w_c
:
You can use :w !cmd
to write the current buffer to the stdin of an external command. From :help :w_c
:
:[range] w [rite] [++ opt]!{cmd}
以
[range]
行作为标准输入执行{cmd}
(请注意'!'
前面的空格).{cmd}
的执行方式与":!{cmd}"
相同,任何'!'
都将替换为先前的命令|:!|
.
:[range]w[rite] [++opt] !{cmd}
Execute
{cmd}
with[range]
lines as standard input (note the space in front of the'!'
).{cmd}
is executed like with":!{cmd}"
, any'!'
is replaced with the previous command|:!|
.
一个相关的命令是:%!cmd
,它执行相同的操作,然后用命令的输出替换当前缓冲区.因此:%!sort
会调用外部sort命令对当前缓冲区进行排序.
A related command is :%!cmd
which does the same thing and then replaces the current buffer with the output of the command. So :%!sort
would invoke the external sort command to sort the current buffer in place.
这篇关于在Vim中将缓冲区缓冲到外部命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!