I'm planning to send emails from inside of VIM via SendEmail, but I have run into some problems.
When piping part of the buffer (or the whole buffer) into SendEmail via the bang (!) operator, the text in my buffer gets replaced 开发者_StackOverflowwith SendEmail's output. So my first question is: how do I pipe a range into an external command and discard it's output (or even better: show it in a cmd window)?
Most of the options I'm giving to SendMail don't change most of the time (like the email server or the from-address), so I don't want to type them every time I send something: I would like a command that has these parameters hard-coded and where I can specify any number of additional parameters (like -u "subject").
Can this be done via the command feature (nargs,range), or do I need to write a function?
The simplest option for this would be to download the RunView plugin from the Vim website and use this. If you let g:runview_filtcmd
be equal to your SendEmail command line, it will take the contents of the current buffer, pipe it to SendEmail and print the output in a separate window. I think this achieves what you need. If you want to use RunView for other stuff, you could omit the g:runview_filtcmd
step and just add this command:
:command! -nargs=* -range=% SendEmail <line1>,<line2>RunView SendEmail -e oneoption -b twooption <args>
and then do:
:SendEmail -u "subject"
or
:'<,'>SendEmail -u "subject"
I haven't tested any of this, but it should work very easily.
If you want to do it manually, you'll probably have to write a function. The way that RunView works is to copy the whole buffer into a register, create a new window, paste the buffer into the end of that window and then filter the new lines through the program. It adds a date/time stamp at the start to separate multiple runs of the same program. This wouldn't be too hard to replicate, but you would probably need a function.
Edit in response to comment:
If you want to send the path as an argument to SendEmail, you could do something like this (I haven't tested this, so it might need tweaking a litle):
command! -nargs=* SendEmailAsAttachment exe '!SendEmail -e oneoption -b twooption -f' expand('%:p') <args>
Note that :exe
concatenates arguments with a space, so calling SendEmailAsAttachment -u "subject"
expands to:
!SendEmail -e oneoption -b twooption -f /path/to/filename.txt -u "subject"
See:
:help expand()
:help :exe
精彩评论