管道 Vim 缓冲区到标准输出 [英] Pipe Vim buffer to stdout
问题描述
我想在管道中间使用 Vim.这个现有帖子看起来像我想要的要做,除非我希望在没有 Python 帮助的情况下做到这一点——只有使用 bash.[它有帮助,环境是 Android 上终端 IDE 应用程序中的 bash shell.]
I'd like to use Vim in the middle of a pipe. This existing post looks like what I'd like to do, except I was hoping to do it without Python's help -- only with bash. [It it helps, the environment is the bash shell in the Terminal IDE app on Android.]
拜托,我知道如何通过内部 Vim 的命令通过管道传输缓冲区.这很好,但不是我想要的.我想退出 Vim 并将活动缓冲区传递给 stdout.
Please, I know how to pipe a buffer through a command from inside Vim. That's great, but not what I want here. I want to exit Vim and pass the active buffer to stdout.
FWIW,我也知道如何将另一个命令作为输入传递给 Vim.再说一次,这不是我想要的.
FWIW, I also know how to pass another command into Vim as input. Again, that's not what I'm trying to get here.
推荐答案
查看 vipe
,它是 moreutils
.它允许您将任何编辑器用作管道的一部分.
Take a look at vipe
which is part of moreutils
. It allows you to use any editor as part of a pipe.
ls -al | vipe | less
要将它与 vim
一起使用,只需确保在 bashrc
或 cshrc
或您使用的任何 shell 中将其设置为默认编辑器.
To use it with vim
just make sure to set it as your default editor in your bashrc
or cshrc
or whatever shell you use.
EDITOR=vim
更新:如果你想要一个 bash
唯一的解决方案,你可以使用这样的脚本
UPDATE: If you want a bash
only solution you could use a script like this
#!/bin/bash
# create temporary file
TMPFILE=`mktemp /tmp/vipe.bashXXXXXXXX`
cat > ${TMPFILE}
vim ${TMPFILE} < /dev/tty > /dev/tty
cat ${TMPFILE}
rm ${TMPFILE}
对于更便携的版本,请更换
For a more portable version please replace
vim ${TMPFILE}
与
${EDITOR} ${TMPFILE}
这篇关于管道 Vim 缓冲区到标准输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!