aboutsummaryrefslogtreecommitdiff
path: root/plugin/cursorline_current.vim
blob: 234450b3c8706a4793967d9a0726f7b9821ce158 (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
32
33
34
"
" cursorline_current: If 'cursorline' is globally on, only enable it for the
" current window, and only when not in insert mode.  Essentially, make
" 'cursorline' follow the actual normal-mode cursor as much as possible.
"
" Author: Tom Ryder <tom@sanctum.geek.nz>
" License: Same as Vim itself
"
if exists('loaded_cursorline_current') || &compatible || v:version < 700
  finish
endif
let loaded_cursorline_current = 1

" Set up hooks for toggling 'cursorline'
augroup cursorline_current
  autocmd!

  " Turn off 'cursorline' for other windows on load
  autocmd VimEnter * call cursorline_current#Load()

  " Turn off 'cursorline' when leaving a window or losing focus.  We call the
  " restore again on BufEnter to handle existent local buffer values for the
  " option overwriting the window value (Vim bug?)
  autocmd WinLeave,FocusLost * call cursorline_current#Suspend()
  autocmd BufEnter,WinEnter,FocusGained * call cursorline_current#Restore()

  " Turn off 'cursorline' when in insert mode
  " Check g:cursorline_current_insert, in case the user doesn't want it
  if get(g:, 'cursorline_current_insert', 1)
    autocmd InsertEnter * call cursorline_current#Suspend()
    autocmd InsertLeave * call cursorline_current#Restore()
  endif

augroup END