如何在 Vim 中的一行中运行两个 shell 命令?

如何在 Vim 中的一行中运行两个 shell 命令?

我想要sortuniq一些台词。我做到了

:'<,'>! sort -f|!uniq

但它给出了一个错误。可以在一行上运行两个命令吗?

答案1

你不需要第二个!。它应该只是:

:'<,'>! sort -f | uniq

:help :!:

Any '!' in {cmd} is replaced with the previous
external command (see also 'cpoptions').  But not when
there is a backslash before the '!', then that
backslash is removed.  Example: ":!ls" followed by
":!echo ! \! \\!" executes "echo ls ! \!".

A '|' in {cmd} is passed to the shell, you cannot use
it to append a Vim command.  See :bar.

这将!uniq是最后运行的命令,并uniq附加:

:!ls
:!echo !uniq

输出:

lsuniq

Press ENTER or type command to continue

相关内容