aboutsummaryrefslogtreecommitdiff
path: root/plugin/cursorline_current.vim
blob: ed590b89024ab9b143202ea110e4228db4138ae4 (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
"
" 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
augroup cursorline_current
  autocmd!

  " Toggle local 'cursorline' state to follow window focus
  autocmd InsertLeave,WinEnter,FocusGained *
        \ call cursorline_current#Restore()
  autocmd InsertEnter,WinLeave,FocusLost *
        \ call cursorline_current#Suspend()

  " If Vim opens with more than one window, set them up correctly
  autocmd VimEnter *
        \ if winnr('$') > 1 | call cursorline_current#Load() | endif

  " Restore the window setting on re-entering a window onto an existing
  " buffer, if there is more than one buffer
  autocmd BufEnter *
        \ if winnr('$') > 1 | call cursorline_current#Restore() | endif

augroup END