You cannot simply put vim inside a pipe, because then Vim cannot display its UI.
ls | vim - | more # Does not work
One way to solve this is to use gvim -f -
inside the pipe, as it opens in a separate window. You need to write the file via :w >> /dev/stdout
and then :quit!
.
Alternatively (and the only way in a console-only non-graphical environment), you could write your own script / function vimAndMore
that takes the command that should be following vim in the pipe as an argument, and goes like this:
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"
}
And change the pipe to this:
ls | vimAndMore more
If multiple pipeline steps are following, you have to use an explicit shell invocation:
ls | vimAndMore sh -c 'tr a-z A-Z | more'