diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2019-06-19 02:39:16 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2019-06-19 11:33:07 +1200 |
commit | f38747fe2912bfaae120512dd79eb528a3f46e99 (patch) | |
tree | 0eb192f5af17ba85974cff6b2cfdf26243be6fb8 /plugin | |
parent | Simplify 'cursorline' reset syntax (diff) | |
download | vim-cursorline-current-f38747fe2912bfaae120512dd79eb528a3f46e99.tar.gz vim-cursorline-current-f38747fe2912bfaae120512dd79eb528a3f46e99.zip |
Complete overhaul for new major release
Fixes -o, -O, and -S related issues.
Diffstat (limited to 'plugin')
-rw-r--r-- | plugin/cursorline_current.vim | 89 |
1 files changed, 71 insertions, 18 deletions
diff --git a/plugin/cursorline_current.vim b/plugin/cursorline_current.vim index 27cc1a0..64278cd 100644 --- a/plugin/cursorline_current.vim +++ b/plugin/cursorline_current.vim @@ -1,6 +1,8 @@ " -" cursorline_current.vim: Apply 'cursorline' only in normal mode in the active -" window. +" cursorline_current.vim: Set 'cursorline' and/or 'cursorcolumn' only in the +" current window, when not in insert mode, and/or when Vim has focus, with +" each of those being configurable with global variables that are checked at +" plugin load time. " " Author: Tom Ryder <tom@sanctum.geek.nz> " License: Same as Vim itself @@ -13,27 +15,78 @@ 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. + " If g:cursorline_current_line is true at plugin load time (defaults to on + " if unset), set 'cursorline' to the user-configured window-global value on + " entering a window, and unset it on leaving. + " + if get(g:, 'cursorline_current_line', 1) + autocmd WinEnter * + \ setlocal cursorline< + autocmd WinLeave * + \ setlocal nocursorline + endif + + " Do the same for 'cursorcolumn' if g:cursorline_current_column is true at + " load time, which again defaults to being on if unset. + " + if get(g:, 'cursorline_current_column', 1) + autocmd WinEnter * + \ setlocal cursorcolumn< + autocmd WinLeave * + \ setlocal nocursorcolumn + endif + + " If g:cursorline_current_insert is set at plugin load time (defaults to on + " if unset), also blank 'cursorline' even in the current window while in + " insert mode. Note that CTRL-C's default behaviour breaks this. + " + if get(g:, 'cursorline_current_insert', 1) + autocmd InsertEnter * + \ doautocmd cursorline_current WinLeave + autocmd InsertLeave * + \ doautocmd cursorline_current WinEnter + endif + + " If g:cursorline_current_focus is set at plugin load time (defaults to on + " if unset), also blank 'cursorline' even in the current window if Vim loses + " focus. This probably only works in the GUI. + " + if get(g:, 'cursorline_current_focus', 1) + autocmd FocusGained * + \ doautocmd cursorline_current WinEnter + autocmd FocusLost * + \ doautocmd cursorline_current WinLeave + endif + + " Stack up BufEnter and BufLeave events to trigger the corresponding window + " events, too; although this often means we set or unset the same option + " twice, it correctly handles entering a new window for a buffer that had + " already loaded. + " + autocmd BufEnter * + \ doautocmd cursorline_current WinEnter + autocmd BufLeave * + \ doautocmd cursorline_current WinLeave + + " When Vim starts up, go through all of the windows in all of the tabs and + " trigger the leave hooks to set 'cursorline' and/or 'cursorcolumn' locally + " off, and then return to the first window of the first tab, and trigger the + " enter hook to restore it to its user-configured window-global value again. + " This is intended to correctly handle -o and -O options from the command + " line, or vimrc files or plugins that open their own windows on Vim + " startup. " autocmd VimEnter * - \ tabdo windo doautocmd WinLeave + \ tabdo windo doautocmd cursorline_current 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. + " If we just loaded a session, however, prevent those VimEnter hooks from + " running by deleting them. The session should have recorded values for + " both options in each of the windows it saved, so we don't need to (and + " shouldn't) mess with them. " - autocmd BufLeave,FocusGained,InsertEnter,WinLeave * - \ setlocal nocursorline + autocmd SessionLoadPost * + \ autocmd! cursorline_current VimEnter augroup END |