From 7cfb8ef1935a8ebe23ca0b8773921d8c11def050 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 4 Aug 2018 21:06:44 +1200 Subject: Spin cursorline_current.vim out into plugin --- .gitmodules | 3 ++ vim/bundle/cursorline_current | 1 + vim/plugin/cursorline_current.vim | 75 --------------------------------------- 3 files changed, 4 insertions(+), 75 deletions(-) create mode 160000 vim/bundle/cursorline_current delete mode 100644 vim/plugin/cursorline_current.vim diff --git a/.gitmodules b/.gitmodules index 46179fab..a695d790 100644 --- a/.gitmodules +++ b/.gitmodules @@ -11,6 +11,9 @@ [submodule "vim/bundle/copy_linebreak"] path = vim/bundle/copy_linebreak url = https://sanctum.geek.nz/code/vim-copy-linebreak.git +[submodule "vim/bundle/cursorline_current"] + path = vim/bundle/cursorline_current + url = https://sanctum.geek.nz/code/vim-cursorline-current.git [submodule "vim/bundle/digraph_search"] path = vim/bundle/digraph_search url = https://sanctum.geek.nz/code/vim-digraph-search.git diff --git a/vim/bundle/cursorline_current b/vim/bundle/cursorline_current new file mode 160000 index 00000000..9481bd3d --- /dev/null +++ b/vim/bundle/cursorline_current @@ -0,0 +1 @@ +Subproject commit 9481bd3d47f9cec47d08757e56a1942325ef989f diff --git a/vim/plugin/cursorline_current.vim b/vim/plugin/cursorline_current.vim deleted file mode 100644 index a552fe95..00000000 --- a/vim/plugin/cursorline_current.vim +++ /dev/null @@ -1,75 +0,0 @@ -" -" 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 -" License: Same as Vim itself -" -if exists('g:loaded_cursorline_current') || &compatible - finish -endif -if !has('autocmd') || !has('windows') || v:version < 700 - finish -endif -let g:loaded_cursorline_current = 1 - -" Suspend 'cursorline' when a window is inactive or inserting -function! s:Suspend() abort - let w:cursorline_current_cache = &l:cursorline - setlocal nocursorline -endfunction - -" Restore 'cursorline' when a window is active and non-insert -function! s:Restore() abort - - " If we don't have a value for 'cursorline' from a previous s:Suspend(), use - " the global value as the default - if !exists('w:cursorline_current_cache') - let w:cursorline_current_cache = &g:cursorline - endif - - " Restore local value to the cached value and clear it - let &l:cursorline = w:cursorline_current_cache - unlet w:cursorline_current_cache - -endfunction - -" Call s:Suspend() on all windows besides the current one -function! s:Load() abort - - " Cache current window index - let l:wcur = winnr() - - " Iterate through all the windows and suspend all but the current one - for l:wnum in range(1, winnr('$')) - if l:wnum != l:wcur - execute l:wnum . 'wincmd w' - call s:Suspend() - endif - endfor - - " Return to the window in which we started - execute l:wcur . 'wincmd w' - -endfunction - -" Set up hooks for toggling 'cursorline' -augroup cursorline_current - autocmd! - - " Turn off 'cursorline' for other windows on load - autocmd VimEnter * call s:Load() - - " Turn off 'cursorline' when leaving a window - autocmd WinLeave * call s:Suspend() - autocmd WinEnter * call s: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 s:Suspend() - autocmd InsertLeave * call s:Restore() - endif - -augroup END -- cgit v1.2.3