Pipe Vim buffer to stdout

vim

Solution

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

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

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}

with

 ${EDITOR} ${TMPFILE}

Problem

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.] 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, I also know how to pass another command into Vim as input. Again, that's not what I'm trying to get here.

Original source

Related problems