从VIM发送电子邮件 [英] Sending email from VIM

查看:177
本文介绍了从VIM发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我打算通过 SendEmail 从VIM内部发送电子邮件,但是我遇到一些问题。

I'm planning to send emails from inside of VIM via SendEmail, but I have run into some problems.


  1. 将缓冲区(或整个缓冲区)的一部分管道传输到SendEmail通过bang( !)运算符,我的缓冲区中的文本被SendEmail的输出替换。所以我的第一个问题是:如何将一个范围管道到一个外部命令中,并丢弃它的输出(甚至更好:在一个cmd窗口中显示)?

  1. When piping part of the buffer (or the whole buffer) into SendEmail via the bang (!) operator, the text in my buffer gets replaced with 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)?

SendMail给我的大部分选项都不会改变大部分时间(比如电子邮件服务器或from-address),所以我不想每次发送一些东西时都输入:我想要一个命令,这些参数硬编码,我可以指定任意数量的附加参数(如-usubject)。

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").

这可以通过命令功能(nargs,range)完成,还是需要写一个函数?

Can this be done via the command feature (nargs,range), or do I need to write a function?

推荐答案

p>最简单的选择是从Vim网站下载 RunView插件并使用它。如果您让g:runview_filtcmd 等于您的SendEmail命令行,则将使用当前缓冲区的内容,将其管道发送到SendEmail,并在单独的窗口中打印输出。我认为这将达到你所需要的。如果你想为其他的东西使用RunView,可以省略 g:runview_filtcmd 步骤,只需添加以下命令:

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>

然后执行:

:SendEmail -u "subject"

:'<,'>SendEmail -u "subject"

我没有测试任何这个,但它应该很容易工作。

I haven't tested any of this, but it should work very easily.

如果您想手动执行,您可能需要编写一个功能。 RunView的工作原理是将整个缓冲区复制到寄存器中,创建一个新窗口,将缓冲区粘贴到该窗口的末尾,然后通过程序过滤新行。它在开始时添加一个日期/时间戳来分隔同一个程序的多个运行。这不是很难复制,但你可能需要一个功能。

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.

编辑响应要发表评论:

如果要将路径作为参数发送到SendEmail,可以这样做(我没有测试过,所以它可能需要调整一下):

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>

请注意,:exe 将参数连接到空间,所以调用 SendEmailAsAttachment -usubject扩展为:

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"

参见:

:help expand()
:help :exe

这篇关于从VIM发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆