user287689
user287689

Reputation:

vim - dim inactive split panes

If you're familiar with the iTerm2 application, you'll know that you can split views similar to vim, and the inactive views are "dimmed."

I usually work in vim with three vertical split views and it would be nice to dim the inactive ones by setting the background color to a darker tone, for example.

Is there a way to do this?

Upvotes: 28

Views: 8868

Answers (6)

Hoblovski
Hoblovski

Reputation: 328

As of 2023, the wincolor might be what you're asking for. It sets the background color (the real background color, not hl-Normal) for a window.

Just add these lines to your vimrc

" dim inactive window
hi WindowInactive ctermbg=243  # or ctermbg=grey, in case you're not using an 256 color terminal
au VimEnter,WinNew,WinEnter   * set wincolor=
au WinLeave * set wincolor=WindowInactive

The result looks like alt

Upvotes: 1

casonadams
casonadams

Reputation: 1200

I created a colorscheme walh that handles this.

It doesn't do many fancy things, it just uses the terminal colors to do the highlights and dimming. This is nice because if you use tmux that dimming will match.

Looks something like this nvim|nvim(focus)|tmux : enter image description here

Upvotes: 0

TaDaa
TaDaa

Reputation: 234

Throwing this out there as a new answer. https://github.com/TaDaa/vimade fades inactive buffers, preserves syntax highlighting, and can also fade signs. I am the author, but I figure this might be useful to some as a newer alternative. Supports nvim and vim8, 256 color terminals, termguicolors, and gui.

Upvotes: 13

Alex
Alex

Reputation: 1688

In neovim(v0.2.1), the following configuration will dim inactive panes:

hi ActiveWindow ctermbg=16 | hi InactiveWindow ctermbg=233
set winhighlight=Normal:ActiveWindow,NormalNC:InactiveWindow

Upvotes: 8

blueyed
blueyed

Reputation: 27878

I have come up with the following solution (using 'colorcolumn' and unsetting 'cursorline'):

" Dim inactive windows using 'colorcolumn' setting
" This tends to slow down redrawing, but is very useful.
" Based on https://groups.google.com/d/msg/vim_use/IJU-Vk-QLJE/xz4hjPjCRBUJ
" XXX: this will only work with lines containing text (i.e. not '~')
function! s:DimInactiveWindows()
  for i in range(1, tabpagewinnr(tabpagenr(), '$'))
    let l:range = ""
    if i != winnr()
      if &wrap
        " HACK: when wrapping lines is enabled, we use the maximum number
        " of columns getting highlighted. This might get calculated by
        " looking for the longest visible line and using a multiple of
        " winwidth().
        let l:width=256 " max
      else
        let l:width=winwidth(i)
      endif
      let l:range = join(range(1, l:width), ',')
    endif
    call setwinvar(i, '&colorcolumn', l:range)
  endfor
endfunction
augroup DimInactiveWindows
  au!
  au WinEnter * call s:DimInactiveWindows()
  au WinEnter * set cursorline
  au WinLeave * set nocursorline
augroup END

View it at my (current) dotfiles: https://github.com/blueyed/dotfiles/blob/master/vimrc#L351

Update I have created a plugin out of it: https://github.com/blueyed/vim-diminactive

Upvotes: 22

Prince Goulash
Prince Goulash

Reputation: 15735

Changing the background colour as you describe would require different colourschemes for different Vim windows. As far as I know this is not possible, as it is a global setting (see this answer from a few days ago).

As a visual aid to which window is active, I find the statusline is usally sufficient. The highlight groups are different for the active window (hi StatusLine) and any innactive windows (hi StatusLineNC). You could either choose a colourscheme with a very stark constrast between them, or edit your favourite colourscheme.

Upvotes: 1

Related Questions