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

A small but visually pleasing feature, and slightly adding to usability, I'd like to have Vim use different background color for the active window.

Here's a sketch of what I am after:

enter image description here

Normally that vim would have all the background in black, but if only the active window had its own color to highlight user's attention. Highlighting just the statusbar only isn't enough!

share|improve this question

Heptite, thank you for the idea.

I just replace WinEnter and WinLeave autocmd's to add / remove line numbers in front of each line:

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

Now is more stylish to track which window is active.

share|improve this answer
This is cool. Too bad I don't fancy line numbers much so it's too unaesthetic. – progo Feb 3 '11 at 9:00

The highlight groups that control the default background color are "Normal" and "NonText". Unfortunately these are "global" highlights and cannot be "localized" on a per-window basis.

However, here is a truly ugly kludgy example:

augroup BgHighlight
    highlight ActiveWindow guibg=lightblue
    autocmd WinEnter * call matchadd('ActiveWindow', '.*', 10, 1682)
    autocmd WinLeave * call matchdelete(1682)
augroup END

doautocmd BgHighlight WinEnter -

Since this is just an example, you'll have to modify this to suit your individual needs, such as adding a ctermbg=... highlight along with the guibg=...

The drawback is that this will only highlight the background of existing text in the files, not the whole line/window. (Like I said, ugly and kludgy.)

share|improve this answer
Nice thinking, but the pattern .* only matches the text of a file; nothing from the rest of the background. In addition, I only got it working in terminal with ctermbg property. Weird... – progo Oct 9 '10 at 8:01
Sorry, I should've been more clear in my answer. I have edited it. – Heptite Oct 9 '10 at 22:10

You must log in to answer this question.

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