Use Vim to send email and check your calendar | Opensource.com

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.

Calendar close up snapshot
Image credits : 
by Dafne Cholet. CC BY-SA 2.0.  
x

Subscribe now

Get the highlights in your inbox every week.

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.

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!

OpenStack source code (Python) in VIM

Make your life as a programmer or sysadmin a little better with these 10 plugins for Vim.
Typewriter keys

Vim offers great benefits to writers, regardless of whether they are technically minded or not.
Calendar close up snapshot

Need to keep your schedule straight? Learn how to do it using open source with these free...

Topics

About the author

Kevin Sonney - 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. Kevin hosts the weekly Productivity Alchemy Podcast. He and his wife, author and illustrator Ursula Vernon, co-host the weekly podcast...