Piping buffer for external team in Vim

I’m like a beginner Vim. I would like to send the contents of the current buffer to the stdin of an external command (say, mail). My ultimate goal is to set a shortcut for sending emails quickly from the current Vim buffer. I suppose this should be trivial, but I could not find a way to send the Vim buffer to an external command. Thanks in advance.

+66
vim external pipe
Oct 23 '11 at 16:13
source share
2 answers

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

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

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

Associated command :%!cmd , which does the same and then replaces the current buffer with the output of the command. Therefore :%!sort will call an external sort command to sort the current buffer.

+98
Oct 23 '11 at 16:22
source share

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

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

This is useful for creating scripts.

For more command line commands, check:

+1
May 25 '15 at
source share



All Articles