使用 Vim 发送邮件和检查日历
邮件 日历

> 
> 在 2020 年用开源实现更高生产力的二十种方式的第十六篇文章中，直接通过文本编辑器管理你的电子邮件和日历。
> 
> 
> 


![](/data/attachment/album/202002/19/185842eyz2znxx1yc2ctnc.jpg)


去年，我在 19 天里给你介绍了 19 个新（对你而言）的生产力工具。今年，我换了一种方式：使用你在使用或者还没使用的工具，构建一个使你可以在新一年更加高效的环境。


### 用 Vim 做（几乎）所有事情，第一部分


我经常使用两个文本编辑器 —— [Vim](https://www.vim.org/) 和 [Emacs](https://www.gnu.org/software/emacs/)。为什么两者都用呢？它们有不同的使用场景，在本系列的后续几篇文章中，我将讨论其中的一些用例。


![](/data/attachment/album/202002/19/185951x5rwckmc0k5sgy0c.png)


好吧，为什么要在 Vim 中执行所有操作？因为如果有一个应用程序是我可以访问的每台计算机上都有的，那就是 Vim。如果你像我一样，可能已经在 Vim 中打发了很多时光。那么，为什么不将其用于**所有事情**呢？


但是，在此之前，你需要做一些事情。首先是确保你的 Vim 具有 Ruby 支持。你可以使用 `vim --version | grep ruby`。如果结果不是 `+ruby`，则需要解决这个问题。这可能有点麻烦，你应该查看发行版的文档以获取正确的软件包。在 MacOS 上，用的是官方的 MacVim（不是 Brew 发行的），在大多数 Linux 发行版中，用的是 vim-nox 或 vim-gtk，而不是 vim-gtk3。


我使用 [Pathogen](https://github.com/tpope/vim-pathogen) 自动加载插件和捆绑软件。如果你使用 [Vundle](https://github.com/VundleVim/Vundle.vim) 或其他 Vim 软件包管理器，则需要调整以下命令才能使用它。


#### 在 Vim 中管理你的邮件


使 Vim 在你的生产力计划中发挥更大作用的一个很好的起点是使用它通过 [Notmuch](https://opensource.com/article/20/1/organize-email-notmuch) 发送和接收电子邮件，和使用 [abook](https://opensource.com/article/20/1/sync-contacts-locally) 访问你的联系人列表。你需要为此安装一些东西。下面的所有示例代码都运行在 Ubuntu 上，因此如果你使用其他发行版，则需要对此进行调整。通过以下步骤进行设置：



```
sudo apt install notmuch-vim ruby-mail
curl -o ~/.vim/plugin/abook --create-dirs https://raw.githubusercontent.com/dcbaker/vim-abook/master/plugin/abook.vim
```

到目前为止，一切都很顺利。现在启动 Vim 并执行 `:NotMuch`。由于是用较旧版本的邮件库 `notmuch-vim` 编写的，可能会出现一些警告，但总的来说，Vim 现在将成为功能齐全的 Notmuch 邮件客户端。


![Reading Mail in Vim](/data/attachment/album/202002/19/185958yvksslj6v5sb57n3.png "Reading Mail in Vim")


如果要搜索特定标签，请输入 `\t`，输入标签名称，然后按回车。这将拉出一个带有该标签的所有消息的列表。`\s` 组合键会弹出 `Search:` 提示符，可以对 Notmuch 数据库进行全面搜索。使用箭头键浏览消息列表，按回车键显示所选项目，然后输入 `\q` 退出当前视图。


要撰写邮件，请使用 `\c` 按键。你将看到一条空白消息。这是 `abook.vim` 插件发挥作用的位置。按下 `Esc` 并输入 `:AbookQuery <SomeName>`，其中 `<SomeName>` 是你要查找的名称或电子邮件地址的一部分。你将在 abook 数据库中找到与你的搜索匹配的条目列表。通过键入你想要的地址的编号，将其添加到电子邮件的地址行中。完成电子邮件的键入和编辑，按 `Esc` 退出编辑模式，然后输入 `,s` 发送。


如果要在 `:NotMuch` 启动时更改默认文件夹视图，则可以将变量 `g:notmuch_folders` 添加到你的 `.vimrc` 文件中：



```
let g:notmuch_folders = [
      \ [ 'new', 'tag:inbox and tag:unread' ],
      \ [ 'inbox', 'tag:inbox' ],
      \ [ 'unread', 'tag:unread' ],
      \ [ 'News', 'tag:@sanenews' ],
      \ [ 'Later', 'tag:@sanelater' ],
      \ [ 'Patreon', 'tag:@patreon' ],
      \ [ 'LivestockConservancy', 'tag:livestock-conservancy' ],
    \ ]
```

Notmuch 插件的文档中涵盖了更多设置，包括设置标签键和使用其它的邮件程序。


#### 在 Vim 中查询日历


![](/data/attachment/album/202002/19/190033mgokolow5kwk4l3l.png)


遗憾的是，似乎没有使用 vCalendar 或 iCalendar 格式的 Vim 日历程序。有个 [Calendar.vim](https://github.com/itchyny/calendar.vim)，做得很好。设置 Vim 通过以下方式访问你的日历：



```
cd ~/.vim/bundle
git clone git@github.com:itchyny/calendar.vim.git
```

现在，你可以通过输入 `:Calendar` 在 Vim 中查看日历。你可以使用 `<` 和 `>` 键在年、月、周、日和时钟视图之间切换。如果要从一个特定的视图开始，请使用 `-view=` 标志告诉它你希望看到哪个视图。你也可以在任何视图中定位日期。例如，如果我想查看 2020 年 7 月 4 日这一周的情况，请输入 `:Calendar -view week 7 4 2020`。它的帮助信息非常好，可以使用 `?` 键参看。


![](/data/attachment/album/202002/19/190102rtk1i4pp76pa1izu.png)


Calendar.vim 还支持 Google Calendar（我需要），但是在 2019 年 12 月，Google 禁用了它的访问权限。作者已在 [GitHub 上的这个提案](https://github.com/itchyny/calendar.vim/issues/156)中发布了一种变通方法。


这样你就在 Vim 中有了这些：你的邮件、地址簿和日历。但是这些还没有完成； 下一篇你将在 Vim 上做更多的事情！


Vim 为作家提供了很多好处，无论他们是否具有技术意识。


需要保持时间表正确吗？了解如何使用这些免费的开源软件来做到这一点。




---


via: <https://opensource.com/article/20/1/vim-email-calendar>


作者：[Kevin Sonney](https://opensource.com/users/ksonney) 选题：[lujun9972](https://github.com/lujun9972) 译者：[wxy](https://github.com/wxy) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
Last year, I brought you 19 days of new (to you) productivity tools for 2019. This year, I'm taking a different approach: building an environment that will allow you to be more productive in the new year, using tools you may or may not already be using.

## Doing (almost) all the things with Vim, part 1

I use two text editors regularly—[Vim](https://www.vim.org/) and [Emacs](https://www.gnu.org/software/emacs/). Why both? They have different use cases, and I'll talk about some of them in the next few articles in this series.

![](https://opensource.com/sites/default/files/uploads/day16-image1.png)

OK, so why do everything in Vim? Because if there is one application that is on every machine I have access to, it's Vim. And if you are like me, you probably already spend a lot of time in Vim. So why not use it for *all the things*?


Before that, though, you need to do some things. The first is to make sure you have Ruby support in Vim. You can check that with **vim --version | grep ruby**. If the result is not **+ruby**, that needs to be fixed. This can be tricky, and you should check your distribution's documentation for the right package to install. On MacOS, this is the official MacVim (not from Brew), and on most Linux distributions, this is either vim-nox or vim-gtk—NOT vim-gtk3.

I use [Pathogen](https://github.com/tpope/vim-pathogen) to autoload my plugins and bundles. If you use [Vundle](https://github.com/VundleVim/Vundle.vim) or another Vim package manager, you'll need to adjust the commands below to work with it.

### Do your email in Vim

A good starting place for making Vim a bigger part of your productivity plan is using it to send and receive email with [Notmuch](https://opensource.com/article/20/1/organize-email-notmuch) using [abook](https://opensource.com/article/20/1/sync-contacts-locally) to access your contact list. You need to install some things for this. All the sample code below is on Ubuntu, so you'll need to adjust for that if you are using a different distribution. Do the setup with:

```
sudo apt install notmuch-vim ruby-mail
curl -o ~/.vim/plugin/abook --create-dirs https://raw.githubusercontent.com/dcbaker/vim-abook/master/plugin/abook.vim
```


So far, so good. Now start Vim and execute **:NotMuch**. There may be some warnings due to the older version of the mail library **notmuch-vim** was written for, but in general, Vim will now be a full-featured Notmuch mail client.

![Reading Mail in Vim Reading Mail in Vim](https://opensource.com/sites/default/files/uploads/productivity_16-2.png)

If you want to perform a search for a specific tag, type **\t**, enter the name of the tag, and press Enter. This will pull up a list of all messages with that tag. The **\s** key combination brings up a **Search:** prompt that will do a full search of the Notmuch database. Navigate the message list with the arrow keys, press Enter to display the selected item, and enter **\q** to exit the current view.

To compose mail, use the **\c** keystroke. You will see a blank message. This is where the **abook.vim** plugin comes in. Hit **Esc** and enter **:AbookQuery <SomeName>**, where <SomeName> is a part of the name or email address you want to look for. You will get a list of entries in the abook database that match your search. Select the address you want by typing its number to add it to the email's address line. Finish typing and editing the email, press **Esc** to exit edit mode, and enter **,s** to send.

If you want to change the default folder view when **:NotMuch** starts up, you can add the variable **g:notmuch_folders** to your **.vimrc** file:

```
let g:notmuch_folders = [
\ [ 'new', 'tag:inbox and tag:unread' ],
\ [ 'inbox', 'tag:inbox' ],
\ [ 'unread', 'tag:unread' ],
\ [ 'News', 'tag:@sanenews' ],
\ [ 'Later', 'tag:@sanelater' ],
\ [ 'Patreon', 'tag:@patreon' ],
\ [ 'LivestockConservancy', 'tag:livestock-conservancy' ],
\ ]
```


There are many more settings covered in the Notmuch plugin's documentation, including setting up keys for tags and using alternate mail programs.

### Consult your calendar in Vim

![](https://opensource.com/sites/default/files/uploads/day16-image3.png)

Sadly, there do not appear to be any calendar programs for Vim that use the vCalendar or iCalendar formats. There is [Calendar.vim](https://github.com/itchyny/calendar.vim), which is very well done. Set up Vim to access your calendar with:

```
cd ~/.vim/bundle
git clone git@github.com:itchyny/calendar.vim.git
```


Now, you can see your calendar in Vim by entering **:Calendar**. You can switch between year, month, week, day, and clock views with the **<** and **>** keys. If you want to start with a particular view, use the **-view=** flag to tell it which one you wish to see. You can also add a date to any of the views. For example, if I want to see what is going on the week of July 4, 2020, I would enter **:Calendar -view week 7 4 2020**. The help is pretty good and can be accessed with the **?** key.

![](https://opensource.com/sites/default/files/uploads/day16-image4.png)

Calendar.vim also supports Google Calendar (which I need), but in December 2019 Google disabled the access for it. The author has posted a workaround in [the issue on
GitHub](https://github.com/itchyny/calendar.vim/issues/156).

So there you have it, your mail, addresses, and calendars in Vim. But you aren't done yet; you'll do even more with Vim tomorrow!

## 4 Comments