diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2019-06-19 11:33:52 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2019-06-19 11:33:52 +1200 |
commit | 903540a2d36de62d6ecc915969f2dd17561cae4b (patch) | |
tree | 5cb8f5698c3114a571bdaa2d34eb70c680aea515 | |
parent | Merge branch 'release/v2.1.0' (diff) | |
parent | Bump VERSION (diff) | |
download | vim-cursorline-current-903540a2d36de62d6ecc915969f2dd17561cae4b.tar.gz vim-cursorline-current-903540a2d36de62d6ecc915969f2dd17561cae4b.zip |
Merge branch 'release/v3.0.0'v3.0.0
* release/v3.0.0:
Complete overhaul for new major release
Simplify 'cursorline' reset syntax
-rw-r--r-- | README.md | 11 | ||||
-rw-r--r-- | VERSION | 2 | ||||
-rw-r--r-- | doc/cursorline_current.txt | 36 | ||||
-rw-r--r-- | plugin/cursorline_current.vim | 89 |
4 files changed, 111 insertions, 27 deletions
@@ -1,9 +1,14 @@ cursorline\_current.vim ======================= -This plugin tweaks the behaviour of the `'cursorline'` option to enable it only -in the current window and when not in insert mode. It essentially makes -`'cursorline'` follow the cursor in normal mode as much as possible. +This plugin tweaks the behaviour of the `'cursorline'` and `'cursorcolumn'` +options to enable them only in the current window, when not in insert mode, +and/or when Vim has focus. + +In its default configuration, it essentially makes `'cursorline'` and +`'cursorcolumn'` follow the cursor around in normal mode as much as possible. +It uses each window's global value of both options as its default, so setting +each option in your `vimrc` before the plugin loads should do the trick. License ------- @@ -1 +1 @@ -2.1.0 +3.0.0 diff --git a/doc/cursorline_current.txt b/doc/cursorline_current.txt index 6a54bb6..4984fec 100644 --- a/doc/cursorline_current.txt +++ b/doc/cursorline_current.txt @@ -1,16 +1,42 @@ -*cursorline_current.txt* For Vim version 7.0 Last change: 2019 Jun 13 +*cursorline_current.txt* For Vim version 7.0 Last change: 2019 Jun 19 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. +This plugin tweaks the behaviour of the 'cursorline' and 'cursorcolumn' +options to enable them only in the current window, when not in insert mode, +and/or when Vim has focus. + +In its default configuration, it essentially makes 'cursorline' and +'cursorcolumn' follow the cursor around in normal mode as much as possible. +It uses each window's global value of both options as its default, so setting +each option in your |vimrc| before the plugin loads should do the trick. REQUIREMENTS *cursorline_current-requirements* This plugin only loads if 'compatible' is not set. +OPTIONS *cursorline_current-options* + + *g:cursorline_current_line* +Set `g:cursorline_current_line` to 0 in your |vimrc| if you don't want +'cursorline' to follow the current window around, and instead prefer each +window to track its own state. This option defaults to 1. + + *g:cursorcolumn_current_column* +Set `g:cursorline_current_column` to 0 in your |vimrc| if you don't want +'cursorcolumn' to follow the current window around, and instead prefer each +window to track its own state. This option defaults to 1. + + *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. + + *g:cursorline_current_focus* +Set `g:cursorline_current_focus` to 0 in your |vimrc| if you don't like the +cursor line switching off when Vim loses focus, which probably only works in +the GUI. This option defaults to 1. + AUTHOR *cursorline_current-author* Written and maintained by Tom Ryder <tom@sanctum.geek.nz>. diff --git a/plugin/cursorline_current.vim b/plugin/cursorline_current.vim index 0b698e3..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 * - \ if &g:cursorline | setlocal cursorline | 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. + " 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 |