2

I use several splits (windows). To quickly identify the splits that has the focus I would like Vim to auromatically adapt the background color of the active split.

Is there a way to do so?

Is it possible to have a different definition of the highlighting group Normal depending if the split (window) is active or not?

enter image description here

1
  • check :h wincolor
    – Maxim Kim
    Mar 17 at 11:15

2 Answers 2

3

You can use :h wincolor for this: https://asciinema.org/a/od7Eh6sVZdw9r65vUrtctZ0PC

Change non-active windows background:

hi DimNormal guibg=#203040

augroup ActiveWin | au!
    au WinEnter * setl wincolor=
    au WinLeave * setl wincolor=DimNormal
augroup END

enter image description here

Of course, you can do the opposite -- change active window background:

hi NormalActive guibg=#203040

augroup ActiveWin | au!
    au WinEnter * setl wincolor=NormalActive
    au WinLeave * setl wincolor=
augroup END
1
  • 1
    Thanks Maxim! It looks like a charm :-) Mar 17 at 11:34
1

Another useful mapping (which I have on <leader><leader><leader>, or 3 spaces for me) is to "blink" the current cursor location in an obvious way:

" ~/.vim/autoload/bk.vim
function bk#cursor#blink(time) abort
  call bk#cursor#hl_on()
  let time_in_ms = float2nr(a:time * 1000)
  if has('timers')
    let _ = timer_start(time_in_ms, {_ -> bk#cursor#hl_off()})
  else
    exec 'sleep'  time_in_ms  'm'
    call bk#cursor#hl_off()
  endif
endfunction

function bk#cursor#hl_on() abort
  set cursorline cursorcolumn
  redraw
endfunction

function bk#cursor#hl_off() abort
  set nocursorline nocursorcolumn
  redraw
endfunction

Along with

nnoremap <leader><leader><leader> :call bk#cursor#blink(0.2)<enter>

(Adjust timing as needed.)

1

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.