管道缓冲区到 Vim 中的外部命令 [英] Piping buffer to external command in Vim
本文介绍了管道缓冲区到 Vim 中的外部命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将当前缓冲区的内容发送到外部命令(如邮件)的标准输入.
I would like to send contents of the current buffer to stdin of external command (like mail).
如何将 Vim 缓冲区发送到外部命令?
How do I send a Vim buffer to an external command?
推荐答案
您可以使用 :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
:
:w_c :write_c
:[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
将调用外部排序命令对当前缓冲区进行排序.来自 :help :range!
:
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. From :help :range!
:
:{range}![!]{filter} [!][arg] :range!
Filter {range} lines through the external program
{filter}. Vim replaces the optional bangs with the
latest given command and appends the optional [arg].
Vim saves the output of the filter command in a
temporary file and then reads the file into the buffer
tempfile. Vim uses the 'shellredir' option to
redirect the filter output to the temporary file.
However, if the 'shelltemp' option is off then pipes
are used when possible (on Unix).
When the 'R' flag is included in 'cpoptions' marks in
the filtered lines are deleted, unless the
:keepmarks command is used. Example:
:keepmarks '<,'>!sort
When the number of lines after filtering is less than
before, marks in the missing lines are deleted anyway.
这篇关于管道缓冲区到 Vim 中的外部命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文