diff options
-rw-r--r-- | VERSION | 2 | ||||
-rw-r--r-- | autoload/cursorline_current.vim | 17 | ||||
-rw-r--r-- | doc/cursorline_current.txt | 10 | ||||
-rw-r--r-- | plugin/cursorline_current.vim | 59 |
4 files changed, 32 insertions, 56 deletions
@@ -1 +1 @@ -0.5.0 +1.0.0 diff --git a/autoload/cursorline_current.vim b/autoload/cursorline_current.vim new file mode 100644 index 0000000..648d633 --- /dev/null +++ b/autoload/cursorline_current.vim @@ -0,0 +1,17 @@ +" 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 + let wcur = winnr() + windo if winnr() != wcur | call cursorline_current#Suspend() | endif + execute wcur . 'wincmd w' +endfunction diff --git a/doc/cursorline_current.txt b/doc/cursorline_current.txt index 838c272..be3e78d 100644 --- a/doc/cursorline_current.txt +++ b/doc/cursorline_current.txt @@ -12,15 +12,7 @@ correctly handle local values for windows. REQUIREMENTS *cursorline_current-requirements* -This plugin only loads if 'compatible' is not set. It requires the |+autocmd| -and |+windows| features. - -OPTIONS *cursorline_current-options* - - *g:cursorline_current_insert* -Set `g:cursorline_current_insert` to 0 in your |vimrc| if you don't like the -cursor line switching off while you're in insert mode. This option defaults to -1. +This plugin only loads if 'compatible' is not set. AUTHOR *cursorline_current-author* diff --git a/plugin/cursorline_current.vim b/plugin/cursorline_current.vim index 9cdb25d..ed590b8 100644 --- a/plugin/cursorline_current.vim +++ b/plugin/cursorline_current.vim @@ -11,56 +11,23 @@ if exists('loaded_cursorline_current') || &compatible || v:version < 700 endif let loaded_cursorline_current = 1 -" Suspend 'cursorline' when a window is inactive or inserting -function! s:Suspend() abort - let w:cursorline_current = &l:cursorline - let &l:cursorline = 0 -endfunction - -" Restore 'cursorline' when a window is active and non-insert -function! s:Restore() abort - let &l:cursorline = get(w:, 'cursorline_current', &g:cursorline) - let w:cursorline_current = &l:cursorline -endfunction - -" Call s:Suspend() on all windows besides the current one -function! s: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 s:Suspend() - endfor - - " Return to the window in which we started - execute wcur . 'wincmd w' - -endfunction - -" Set up hooks for toggling 'cursorline' +" Set up hooks augroup cursorline_current autocmd! - " Turn off 'cursorline' for other windows on load - autocmd VimEnter * call s:Load() + " Toggle local 'cursorline' state to follow window focus + autocmd InsertLeave,WinEnter,FocusGained * + \ call cursorline_current#Restore() + autocmd InsertEnter,WinLeave,FocusLost * + \ call cursorline_current#Suspend() - " 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 s:Suspend() - autocmd BufEnter,WinEnter,FocusGained * call s:Restore() + " If Vim opens with more than one window, set them up correctly + autocmd VimEnter * + \ if winnr('$') > 1 | call cursorline_current#Load() | endif - " 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 s:Suspend() - autocmd InsertLeave * call s:Restore() - 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 |