aboutsummaryrefslogtreecommitdiff
path: root/autoload/cursorline_current.vim
blob: 36bb210a00ab9a41abd5ba67f5f624d4e3b4afbe (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
" Suspend 'cursorline' when a window is inactive or inserting
function! cursorline_current#Suspend() abort
  let w:cursorline_current = &l:cursorline
  let &l:cursorline = 0
endfunction

" Restore 'cursorline' when a window is active and non-insert
function! cursorline_current#Restore() abort
  let &l:cursorline = get(w:, 'cursorline_current', &g:cursorline)
  let w:cursorline_current = &l:cursorline
endfunction

" Call cursorline_current#Suspend() on all windows besides the current one
function! cursorline_current#Load() abort

  " Cache current window index
  let wcur = winnr()

  " Iterate through all the windows and suspend all but the current one
  for wnum in range(1, winnr('$'))
    if wnum == wcur
      continue
    endif
    execute wnum . 'wincmd w'
    call cursorline_current#Suspend()
  endfor

  " Return to the window in which we started
  execute wcur . 'wincmd w'

endfunction