Pipe Vim buffer to stdout

后端 未结 5 820
执念已碎
执念已碎 2021-02-07 02:37

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

5条回答
  •  日久生厌
    2021-02-07 02:45

    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}
    

提交回复
热议问题