VimはUIを表示できないため、単純にvimをパイプ内に配置することはできません。
ls | vim - | more # Does not work
これを解決する1つの方法はgvim -f -
、パイプが別のウィンドウで開くため、パイプの内側で使用することです。を介してファイルを書き込む必要があり:w >> /dev/stdout
ます:quit!
。
あるいは(そしてコンソールのみの非グラフィカル環境での唯一の方法)、vimAndMore
パイプ内のvimに続くコマンドを引数として取る独自のスクリプト/関数を記述して、次のようにすることができます。
vimAndMore()
{
TMPFILE=/tmp/pipecontents
# Slurp stdin into the temp file.
cat - > "$TMPFILE" || exit $?
# Reconnect stdin to the terminal, so that Vim doesn't complain with "Warning:
# Input is not from a terminal", and the terminal is kept intact.
exec 0</dev/tty
# Launch the editor.
"${EDITOR:-vim}" "$TMPFILE" || exit $?
# Carry on with the pipe.
cat "$TMPFILE" | exec "$@"
rm "$TMPFILE"
}
そして、パイプを次のように変更します。
ls | vimAndMore | more