Use Vim to send email and check your calendar

Manage your email and calendar right from your text editor in the sixteenth in our series on 20 ways to be more productive with open source in 2020.
83 readers like this.
Poll: Upcoming open source conferences

by Dafne Cholet. CC BY-SA 2.0.

 

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 and Emacs. Why both? They have different use cases, and I'll talk about some of them in the next few articles in this series.

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 to autoload my plugins and bundles. If you use Vundle 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 using abook 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

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

Sadly, there do not appear to be any calendar programs for Vim that use the vCalendar or iCalendar formats. There is 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.

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
.

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!

What to read next

Awesome vim plugins for writers

Vim is one of the most popular text editors among programmers, web developers, and power users of GNU/Linux. This is not surprising, because Vim offers high-speed editing, has…

Tags
User profile image.
Kevin Sonney is a technology professional, media producer, and podcaster. A Linux Sysadmin and Open Source advocate, Kevin has over 25 years in the IT industry, with over 15 years in Open Source. He currently works as an SRE at elastic.

4 Comments

This is kinda counter intuitive argument you're making there. The post starts with "you have vim" and then goes to installing a lot of software around vim. So, it only goes to reason that if you need to install ruby-mail and notmuch, then why not install a real email client? Because you're not really using Vim to read mail, just to display it...

This is sorta like claiming "here's how you read email in bash" and then explaining how to install mutt. It's running in your bash shell, no? You can only stretch this point so far.

Vim command utilization new technique

For anyone who has issues with the vim-notmuch plugin giving "Deprecated", it's an easy fix. The method that is being used in the plugin has been deprecated and can easily be fixed by using the newer version. edit the file as follows:

vi ~/.vim/plugin/notmuch.vim

then in vim press esc and type the following:

:%s/Field\.new/Field.parse/g

Then save and restart ( esc and :wq! ) and restart vim. NotMuch should work with no deprecated issues anymore.

Everyone: missing from the article is "sudo gem install mail"

Creative Commons LicenseThis work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License.