Piping buffer to external command in Vim

前端 未结 2 1335
感情败类
感情败类 2020-12-02 06:27

I am kind of a Vim novice. I would like to send contents of the current buffer to stdin of external command (lets say mail). My final purpose is to set a shortcut to quickly

相关标签:
2条回答
  • 2020-12-02 06:38

    Here is example how to send the current buffer to external stdin from the command line:

    vim -es +"w >> /dev/stdout" -cq! /etc/hosts
    

    It's useful for scripting purposes.

    For more command-line tricks, check:

    • How to write whole buffer to standard output from the command line?
    0 讨论(0)
  • 2020-12-02 07:01

    You can use :w !cmd to write the current buffer to the stdin of an external command. From :help :w_c:

    :[range]w[rite] [++opt] !{cmd}

    Execute {cmd} with [range] lines as standard input (note the space in front of the '!'). {cmd} is executed like with ":!{cmd}", any '!' is replaced with the previous command |:!|.

    A related command is :%!cmd which does the same thing and then replaces the current buffer with the output of the command. So :%!sort would invoke the external sort command to sort the current buffer in place.

    0 讨论(0)
提交回复
热议问题