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
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:
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.