aboutsummaryrefslogtreecommitdiff
path: root/autoload/cursorline_current.vim
blob: 0c56c8da57eac4bc0dda6a2b177dea4bc7ebdcac (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
" Suspend 'cursorline' when a window is inactive or inserting
function! cursorline_current#Suspend() abort
  let w:cursorline = &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', &g: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