Making the active window in vim more obvious

My workspace is normally one very big xterm with vim, split into six or more buffers. It would be really helpful if it were more obvious which one was the active buffer. Right now I'm using the presence of line numbers for this:

augroup BgHighlight
    autocmd!
    autocmd WinEnter * set number
    autocmd WinLeave * set nonumber
augroup END

but this means that when I change buffers my code jumps left or right, which is annoying. Plus, I'd like to be able to see which is line 94 even in an inactive buffer. So is there any way of changing the colours of the line numbers in the active buffer?


Solution 1:

Following your template, you could vary different properties, such as colorcolumn:

augroup BgHighlight
    autocmd!
    autocmd WinEnter * set colorcolumn=80
    autocmd WinLeave * set colorcolumn=0
augroup END

This will color column 80 on your current window, while disabling it on the others. It's a bit less jarring than setting/unsetting line numbers.

An even less intrusive option, if you are used to highlighting the current line (set cul), is to do:

augroup BgHighlight
    autocmd!
    autocmd WinEnter * set cul
    autocmd WinLeave * set nocul
augroup END

It all comes down to your usage and what you're willing to put up with.

Solution 2:

The color of the statusline is the most usual way to know which window is active. It is defined in your colorscheme with these two lines:

hi StatusLine   ctermfg=15  guifg=#ffffff ctermbg=239 guibg=#4e4e4e cterm=bold gui=bold
hi StatusLineNC ctermfg=249 guifg=#b2b2b2 ctermbg=237 guibg=#3a3a3a cterm=none gui=none

The first is for the current window, the second is for the "non-current" window.

This is an excerpt from xoria256, you should adapt the colors to your colorscheme.

But you could try something like that (beware, the colors in the second line are completely random):

augroup NrHighlight
  autocmd!
  autocmd WinEnter * hi LineNr ctermfg=247 guifg=#9e9e9e ctermbg=233 guibg=#121212
  autocmd WinLeave * hi LineNr ctermfg=274 guifg=#e9e9e9 ctermbg=133 guibg=#212121
augroup END

Solution 3:

See also my plugin which dims inactive windows: https://github.com/blueyed/vim-diminactive

Solution 4:

This is what I do:

augroup BgHighlight
    autocmd!
    autocmd WinEnter * set relativenumber
    autocmd WinLeave * set norelativenumber
augroup END

Relative numbers are just an aid for calculating the repeat amount of commands, there is no use for them in a window you are not editing.