Vim Tip #35: Status Line: Mode Display

2022-11-06(Sun)

tags: Vim

Vim Tips

Also see Status Line, which will introduce you to the basics of configuring the Status Line.

Vim allows you to reconfigure a lot of things about it. I've already rewritten the Tab Line, so - as much as I love Airline - I'm not surprised to find myself rewriting the Status Line as well. It's always bothered me that Airline demands its own specialty font, which can be problematic on remote machines. But this rabbit hole goes very, very deep (more so than Tab Lines), so I'll be addressing this in pieces.

This borrows heavily from other sources - most notably https://stackoverflow.com/questions/66166505/how-can-i-show-command-mode-in-statusline-when-entering-command-line-mode .

let g:currentmode={
    \ 'n'  : 'NORMAL',
    \ 'no' : 'NORMAL,OP',
    \ 'v'  : 'VISUAL',
    \ 'V'  : 'V-LINE',
    \ '^V' : 'V-BLOCK',
    \ 's'  : 'SELECT',
    \ 'S'  : 'S-LINE',
    \ '^S' : 'S-BLOCK',
    \ 'i'  : 'INSERT',
    \ 'R'  : 'REPLACE',
    \ 'Rv' : 'V-REPLACE',
    \ 'c'  : 'COMMAND',
    \ 'cv' : 'VIM EX',
    \ 'ce' : 'EX',
    \ 'r'  : 'PROMPT',
    \ 'rm' : 'MORE',
    \ 'r?' : 'CONFIRM',
    \ '!'  : 'SHELL',
    \ 't'  : 'TERMINAL'
    \}

set statusline+=\ %{g:currentmode[mode()]}\  " The current mode

I've simplified this slightly from the quoted source: you may or may not consider this an improvement. Put this in your ~/.vimrc (or ~/.config/nvim/init.vim if you're using NeoVim) and it will be added to your already-existing statusline setup. There are caveats to that statement: if you're using Airline or any other bundled setup to control your statusline, it will probably override anything you do to the status line, so turn those plugins off.

As long as I've used Vim, I had no idea it had so many modes. Everyone knows "NORMAL" and "INSERT," and over the years I'd become aware of "REPLACE" and "OPERATOR PENDING," but ... that's a lot.

Another possible (and in fact likely) modification in my case is to use the detected mode to set a colour for this section of the status line. That will require adding a function to do the look-up and set the colours according to some scheme incorporated in the function ...