Making My Own Vim Statusline

Written By: Jake Bauer | Posted: 2020-02-24 | Last Updated: 2020-02-24

I was playing around with a plugin that I came across while browsing r/vim called vim-startuptime. It's a vim plugin by Daniel Steinberg (dstein64 on GitHub) which measures the amount of time each component of your vim configuration takes to load when you launch vim. This way, you can get an idea of what is taking the most time and causing your previously-lightning-quick text editor to take what feels like an eternity to become ready.

I took 5 measurements, back to back, opening my vimrc and I noticed that my vim configuration was taking roughly 132.35ms on average to finish loading (with a standard deviation of 2.69ms). Although that sounds fast, it was definitely noticeable as it was just past the 100ms commonly accepted limit for a user interface to feel like it was responding instantaneously. Below is a video showing a very clear and noticable delay when launching vim:

Although vim-startuptime showed me a graph of each component's execution time, the statistics shown didn't reveal a specific component that could be causing the startuptime to be this long. In fact, it appeared that it was the cumulative effect of loading each of my plugins and parsing my vimrc which was causing the overall startuptime to be noticeably long. So, I decided to figure out if this was the case by experimenting. I removed all of my plugins (but kept my vimrc the same) and, as expected, my startuptime dropped to the 20ms range. One-by-one, I added my plugins back in. To my surprise, I noticed a huge jump in startuptime when I added vim-airline back in. Vim-airline was the plugin that I was using to display an aesthetically pleasing statusbar and buffer bar at the bottom and top of my vim windows respectively and it was causing my startuptime to effectively double! No other plugin had that drastic of an effect.

I decided, then, that I was going to replace vim-airline with my own custom statusline.

I used a blog post by Irrellia to get me started and found that it was actually really easy to make a good-looking and functional statusline. About 100 lines of vimscript later and I had a customized statusline that fulfilled my needs and looked really good (in my humble opinion). I also put my custom statusline into a plugin folder in my .vim/bundle/ directory so that it would be automatically loaded by Pathogen as if it was a regular plugin.

I will fully admit that I pretty much copied the colour scheme used in the tutorial verbatim because I really liked the way it looked. Little did I know, this would start a whole week of tinkering with my setup (I'll get into that in an upcoming blog post).

Something that I missed from vim-airline was that top line which displayed a list of open buffers and highlighted the currently active buffer. I thought about doing it myself but the implementation looked a little too complicated for my mediocre vimscript skills. Instead, I replaced that specific functionality with another really lightweight plugin called vim-buftabline.

Once I was finished tinkering, I tested my new custom statusline (with the vim-buftabline plugin too) using the same method which I used to test my previous configuration and found that the average startup time had dropped to a mere 66.85ms (with a standard deviation of 1.79ms)! That's a roughly 2 times improvement in speed; it felt instantaneous again! Here, have a look at the video below:

I've put my statusline in its own git repository which you can find on sourcehut or on my self-hosted git server. I've decided to call it vim-fastline. I don't plan to do anything even remotely comparable to vim-airline with it but I want to make it available in case others want to hack on it.

Not only was it fun and educational to program my own statusline, it had significant performance benefits, and it now sort of feels like my vim configuration is much more personal and not just a collection of plugins. It feels like it's "my configuration" if that makes sense. I encourage you to give it a try even if you're happy with your current configuration.

Happy hacking!