diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2019-06-10 22:42:39 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2019-06-10 22:42:39 +1200 |
commit | 7d7f94b61580eb18fcdb31e2122ca5584c0951a0 (patch) | |
tree | 3c1f37a5bb76d33bddc200cdec4b0f1eb8c5692c | |
parent | Merge branch 'release/v1.0.0' (diff) | |
parent | Bump VERSION (diff) | |
download | vim-cursorline-current-7d7f94b61580eb18fcdb31e2122ca5584c0951a0.tar.gz vim-cursorline-current-7d7f94b61580eb18fcdb31e2122ca5584c0951a0.zip |
Merge branch 'release/v2.0.0'v2.0.0
* release/v2.0.0:
Add documentary comments
Rearrange autocmds
Backport to Vim 7.0
Support tabs on startup as well as windows
Refactor and simplify, remove autoload
-rw-r--r-- | VERSION | 2 | ||||
-rw-r--r-- | autoload/cursorline_current.vim | 17 | ||||
-rw-r--r-- | doc/cursorline_current.txt | 7 | ||||
-rw-r--r-- | plugin/cursorline_current.vim | 38 |
4 files changed, 25 insertions, 39 deletions
@@ -1 +1 @@ -1.0.0 +2.0.0 diff --git a/autoload/cursorline_current.vim b/autoload/cursorline_current.vim deleted file mode 100644 index 648d633..0000000 --- a/autoload/cursorline_current.vim +++ /dev/null @@ -1,17 +0,0 @@ -" 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 be3e78d..a3d67a5 100644 --- a/doc/cursorline_current.txt +++ b/doc/cursorline_current.txt @@ -1,14 +1,11 @@ -*cursorline_current.txt* For Vim version 7.0 Last change: 2019 May 25 +*cursorline_current.txt* For Vim version 7.0 Last change: 2019 Jun 10 DESCRIPTION *cursorline_current* This plugin tweaks the behaviour of the 'cursorline' option to enable it only in the current window, when not in insert mode, and (if supported) when Vim has focus. It essentially makes 'cursorline' follow the cursor in normal mode -as much as possible. - -It uses the global value of 'cursorline' as its default, and should also -correctly handle local values for windows. +as much as possible. It uses the global value of 'cursorline' as its default. REQUIREMENTS *cursorline_current-requirements* diff --git a/plugin/cursorline_current.vim b/plugin/cursorline_current.vim index ed590b8..034a422 100644 --- a/plugin/cursorline_current.vim +++ b/plugin/cursorline_current.vim @@ -1,7 +1,6 @@ " -" 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. +" 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 @@ -11,23 +10,30 @@ if exists('loaded_cursorline_current') || &compatible || v:version < 700 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 + " 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 * - \ if winnr('$') > 1 | call cursorline_current#Load() | endif + \ 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 * + \ let &l:cursorline = &g:cursorline - " 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 + " 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 * + \ let &l:cursorline = 0 augroup END |