aboutsummaryrefslogtreecommitdiff
path: root/plugin/cursorline_current.vim
blob: 27cc1a020b60601ab04c8a5d14a23b507372a235 (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
35
36
37
38
39
"
" cursorline_current.vim: Apply 'cursorline' only in normal mode in the active
" window.
"
" 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

augroup cursorline_current
  autocmd!

  " On opening Vim, we might have to get initial windows into the right state.
  " Run the hook for leaving windows on every window, and then move back to
  " the first window and run the hook for entering a window.
  "
  autocmd VimEnter *
        \ tabdo windo doautocmd WinLeave
  autocmd VimEnter *
        \ tabfirst | 1 wincmd w | doautocmd WinEnter

  " On entering a buffer, the Vim application gaining focus, leaving insert
  " mode, or entering a window, set the local value of the 'cursorline' option
  " to the same as the global value, to correspond with an active state.
  "
  autocmd BufEnter,FocusGained,InsertLeave,WinEnter *
        \ setlocal cursorline<

  " On leaving a buffer, the Vim application window losing focus, entering
  " insert mode, or leaving a window, turn off the 'cursorline' option for the
  " linked window, so that if it's on, it will only be in the active one.
  "
  autocmd BufLeave,FocusGained,InsertEnter,WinLeave *
        \ setlocal nocursorline

augroup END