Trying Out Vim Plugins (Series)

Part 5 - vim-airline


Today we’re trying out vim-airline, the statusline plugin.

vim-airline

vim-airline improves upon Vim’s existing statusline.

Out of the box, vim-airline adds a mode indicator (INSERT), a current status indicator with e.g. version control change numbers (+0 ~0 -0), the file path and unsaved status indicator, the file format (markdown), the file encoding (utf-8[unix]), the total word count (150 words), a relative position indicator (17%), a current line/total lines indicator (16/20), a current column indicator, and a section for external plugins. The Readme provides more exact descriptions of each section.

Usage

Install the plugin and re-open Vim to see your new status bar. That’s it!

Configuration

In my estimation, few if any parts of a terminal-based app UI attract more customization than the statusline. Only the terminal prompt itself might compete. (I’ve added both 🍔 and 🦊 emoji to mine over the years.) vim-airline, naturally, offers extensive customization.

Themes

Where better to start than with themes? I went with the plugin project’s official themes.

bubblegum caught my eye, as did minimalist, deus, and solarized dark. I prefer a minimum of distraction and brightness, in keeping with my white-on-black “dark mode” theme for Vim as a whole, and all of these fit that criteria.

Fonts

This was when I realized something was off about my terminal: I didn’t see any of the arrows I saw in the screenshots! And I had been looking forward to those, too.

Per recommendations, I installed and enabled Powerline fonts:

(In Debian/Ubuntu)

$ sudo apt-get install fonts-powerline
(In the Vim config)

let g:airline_powerline_fonts = 1

Unfortunately, I encountered a subtle alignment issue with the arrows:

Screenshot of an alignment issue in the statusline

I tried the Fira Code font instead. Fira Code Regular at size 11 seemed to do the trick. I’m not 100% sold on this particular font but I’m giving it a try. I did go with the Ubuntu default font out of pure inertia, after all, and what better time to adjust other parts of my interface than while I’m customizing Vim?

Themes, Revisited

With those issues resolved, I settled on the minimalist theme:

let g:airline_theme='minimalist'

Unlike other themes, its colors remain the same when switching between normal, insert, and other editor modes. I found that much less distracting.

Statusline Format

Even with a subtle theme, I still found the contents of the statusline too cluttered for my taste. Note: I tend towards narrow windows so your mileage may vary.

Note: You can refresh the vim-airline status bar from inside of Vim with:

:AirlineRefresh

Sections x and y didn’t feel especially useful to me so I emptied them out:

let g:airline_section_x = ''
let g:airline_section_y = ''

I found the word count section distracting, as well, so I disabled it. (A habit from my NaNoWriMo days, when I would avoid visible word counts or timer countdowns in order to focus on the act of drafting to the exclusion of progress tracking.)

let g:airline#extensions#wordcount#enabled = 0

I also adjusted section z:

let g:airline_section_z = '🦊 %2p%% ☰ %3l/%3L %3c'

vim-airline uses the standard Vim statusline format. To illustrate with the last part:

  • - A Unicode character from the default format string
  • %3c - A field (%), specifically the column under the cursor (c), with a minimum size of three characters (3)

I added a minimum length to all these numbers in order to minimize the frequency of section width changes (e.g. from line 99 to line 100). This reduces one otherwise pernicious distraction.

I added the 🦊 emoji at the start as a personal touch. Isn’t she adorable?

After all that, I feel content with my statusline. I look forward to tweaking it for specific filetypes, projects, and environments going forward. How might you change your status line?

Notes

vim-airline doesn’t seem to play nice with Goyo so I wrote this post with only the former enabled. That said, combining the two does defeat the purpose of Goyo so that was no great less.

In Closing

I loved writing this series on Vim plugins. Researching this plugin, in particular, pointed me to many, many other plugins worth checking out. I hope that you find more useful plugins there and that you enjoyed reading this. Now go out there and have some Vim fun!

Previous Plugins