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 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?

6 Answers 6


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

augroup BgHighlight
    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 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.


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 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
  • I'd already tried changing the LineNr highlighting on WinEnter/WinLeave, but it appears that LineNr colouring is global.
    – DrHyde
    Feb 3, 2012 at 14:58
  • Yes, and I had to wait your comment to remember that. So, no, if LineNr is global there is obviously no way to change it in a specific window. Don't you think the statusline is enough?
    – romainl
    Feb 3, 2012 at 15:48
  • I wondered if there might be some other per-window version of LineNr. And no, I don't think the status line is enough. It helps, but I'd like more. One problem with using the status line is that having the active window indicator at the bottom of the window is the exact opposite of what we have just about everywhere else - a title bar at the top of a window that changes colour - so there's a moment's pause to think "oh yeah, vim does this the other way round". Whereas line numbers are always, in every application, in the same place.
    – DrHyde
    Feb 3, 2012 at 22:22
  • I'd really like it if you could change window background color, but it sounds like, from the above, this isn't possible. Nov 1, 2013 at 14:23
  • Using hi StatusLine... and hi StatusLineNC... works like a charm!
    – Luc M
    Sep 5, 2019 at 14:36

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


This is what I do:

augroup BgHighlight
    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.


You can add this to your ~/.vimrc, which will make the inactive windows' status bars have a dark gray background to differentiate from the active window's white status bar.

highlight StatusLineNC cterm=bold ctermfg=white ctermbg=darkgray

See this screenshot example. The middle window is active (white status bar). The left and right windows are inactive (dark gray status bar).

enter image description here


I like to hide the cursorline for inactive windows

augroup CursorLineOnlyInActiveWindow
  autocmd VimEnter,WinEnter,BufWinEnter * setlocal cursorline
  autocmd WinLeave * setlocal nocursorline
augroup END  

(thanks to https://codeyarns.com/2013/02/07/how-to-show-cursorline-only-in-active-window-of-vim/)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.