Artificial truth

archives | latest | homepage | atom/rss/twitter

The more you see, the less you believe.

Lightweight and sexy status bar in vim
Sun 07 January 2018 — download

I'm a big fan of vim, but always thought that the vanilla statusline is both ugly and useless. During the years, I've been a user of vim-powerline, vim-airline and finally vim-lightline. Yesterday night, I was both too drunk and tired to do anything useful, so I was wondering if I could get the same sexy statusbar without using any plugin, and it turned out that it's pretty easy, once you know that:

  • you have to escape spaces with \
  • everything between %{…} will be evaluated
  • you can set colours with %#your_colour_name#
  • everything you need to know is in :help statusline

I'm a bit dissatisfied by my hack to get the current mode in a nice way, but I didn't manage to come up with something better. But since my vim is already notably faster when I'm scrolling, I don't care that much.

set statusline=
set statusline+=%#DiffAdd#%{(mode()=='n')?'\ \ NORMAL\ ':''}
set statusline+=%#DiffChange#%{(mode()=='i')?'\ \ INSERT\ ':''}
set statusline+=%#DiffDelete#%{(mode()=='r')?'\ \ RPLACE\ ':''}
set statusline+=%#Cursor#%{(mode()=='v')?'\ \ VISUAL\ ':''}
set statusline+=\ %n\           " buffer number
set statusline+=%#Visual#       " colour
set statusline+=%{&paste?'\ PASTE\ ':''}
set statusline+=%{&spell?'\ SPELL\ ':''}
set statusline+=%#CursorIM#     " colour
set statusline+=%R                        " readonly flag
set statusline+=%M                        " modified [+] flag
set statusline+=%#Cursor#               " colour
set statusline+=%#CursorLine#     " colour
set statusline+=\ %t\                   " short file name
set statusline+=%=                          " right align
set statusline+=%#CursorLine#   " colour
set statusline+=\ %Y\                   " file type
set statusline+=%#CursorIM#     " colour
set statusline+=\ %3l:%-2c\         " line + column
set statusline+=%#Cursor#       " colour
set statusline+=\ %3p%%\                " percentage

The only fancy features that it comes with are dynamic colouring of the current mode and indication of the paste and spellcheck status.

My old bar:

old status bar

My new bar:

new status bar

The differences are intended.

You can find the rest of my vimrc here.