Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question

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.

share|improve this answer
+1 for the cul/nocul trick, very nice. – David Pope Mar 7 '12 at 5:29

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
share|improve this answer
I'd already tried changing the LineNr highlighting on WinEnter/WinLeave, but it appears that LineNr colouring is global. – DrHyde Feb 3 '12 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 '12 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 '12 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. – Jonathan Hartley Nov 1 '13 at 14:23

See also my plugin which dims inactive windows:

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .