├── .github └── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md ├── .gitignore ├── CursorLineCurrentWindow.manifest ├── README.md ├── doc └── CursorLineCurrentWindow.txt └── plugin └── CursorLineCurrentWindow.vim /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: The plugin isn't working at all or shows wrong or unexpected behavior 4 | title: '' 5 | labels: '' 6 | 7 | --- 8 | **Frequent Issues** 9 | 10 | * **Sudden problems after updating**: Did you check out the default _master_ branch? Unless you want to participate in feature development and alpha testing, I would recommend that you switch from _master_ to the _stable_ branch; this way, you'll only update to released versions that are (hopefully) better tested and documented. 11 | * **Neovim**: I don't explicitly consider nor test Neovim compatibility; my plugins are written for Vim. If a plugin can be made to work on Neovim with trivial changes, I wouldn't mind including them, but anything more involved should in my opinion be filed as a compatibility bug against Neovim (as its homepage proclaims: _Fully compatible with Vim's editing model and the Vimscript language._) 12 | 13 | **Describe the bug** 14 | 15 | _A clear and concise description of what the bug is._ 16 | 17 | **How to Reproduce** 18 | 19 | _Detailed steps to reproduce the behavior._ 20 | 21 | **Expected Behavior** 22 | 23 | _A clear and concise description of what you expected to happen._ 24 | 25 | **Environment** 26 | - Plugin version (e.g. stable version _1.10_) / revision _a1b2c3d4_ from the master branch 27 | - Vim version (e.g. _8.1.1234_) Or paste the result of `vim --version`. 28 | - OS: (e.g. _Ubuntu 18.04_, _Windows 10 1809_, _macOS 10.14_) 29 | - Install method: (e.g. manually via Vimball or ZIP file, GitHub clone as pack plugin, Plugin manager _NAME_) 30 | - Other plugins / additional context if you think this could be important 31 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an enhancement for the plugin 4 | title: '' 5 | labels: enhancement 6 | 7 | --- 8 | 9 | **Motivation** 10 | 11 | _A clear and concise description of what currently is hard to do._ 12 | 13 | **Request and Purpose** 14 | 15 | _A clear and concise description of what you want to happen. Possible fit criteria._ 16 | 17 | **Alternatives** 18 | 19 | _A clear and concise description of any alternative solutions or features you've considered._ 20 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.msgout 2 | *.msgresult 3 | *.out 4 | *.tap 5 | doc/*.description 6 | doc/*.install 7 | tags 8 | -------------------------------------------------------------------------------- /CursorLineCurrentWindow.manifest: -------------------------------------------------------------------------------- 1 | plugin/CursorLineCurrentWindow.vim 2 | doc/CursorLineCurrentWindow.txt 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | CURSOR LINE CURRENT WINDOW 2 | =============================================================================== 3 | _by Ingo Karkat_ 4 | 5 | DESCRIPTION 6 | ------------------------------------------------------------------------------ 7 | 8 | The 'cursorline' setting makes it easy to locate the cursor position. However, 9 | when there are split windows, each one shows its cursor line, and the only 10 | indication of the currently active window is the different 'statusline' 11 | highlighting (with hl-StatusLine vs. hl-StatusLineNC). 12 | 13 | This plugin avoids the clutter of multiple highlighted screen lines with split 14 | windows by disabling the 'cursorline', 'cursorcolumn', and/or 'wincolor' 15 | settings for all but the current window. Unlike a simplistic solution with a 16 | few autocmds, this plugin still allows for exceptions like disabling the 17 | cursorline for a particular window or making it permanent for (another) 18 | window. 19 | 20 | ### SEE ALSO 21 | 22 | - The RelativeNumberCurrentWindow plugin ([vimscript #4461](http://www.vim.org/scripts/script.php?script_id=4461)) enables the 23 | 'relativenumber' setting only for the current window. 24 | 25 | ### RELATED WORKS 26 | 27 | The basic idea is outlined in the Vim Tips Wiki: 28 | http://vim.wikia.com/wiki/Highlight_current_line 29 | - cursorline\_current.vim ([vimscript #5740](http://www.vim.org/scripts/script.php?script_id=5740)) enables cursorline only in the 30 | current window and when not in insert mode. 31 | 32 | USAGE 33 | ------------------------------------------------------------------------------ 34 | 35 | Globally enable 'cursorline', 'cursorcolumn' and/or 'wincolor' in your 36 | vimrc; e.g. 37 | :set cursorline cursorcolumn 38 | After sourcing this plugin, the option(s) will only be active for the current 39 | window. So with multiple split windows, only one of them, the one where the 40 | cursor is in, will have 'cursorline' and 'cursorcolumn' enabled. 41 | 42 | Disable cursorline for the current window via: 43 | :setlocal nocursorline 44 | This will persist even after moving away and back to the window. 45 | 46 | Disable cursorline globally via: 47 | :set nocursorline 48 | As soon as you enter a window, its line highlighting will vanish. 49 | 50 | For some kind of files it is helpful to keep the line highlighting active, 51 | e.g. to serve as a ruler. You can keep the highlighting for a particular 52 | window by setting a window-local variable: 53 | :let w:persistent_cursorline = 1 54 | 55 | INSTALLATION 56 | ------------------------------------------------------------------------------ 57 | 58 | The code is hosted in a Git repo at 59 | https://github.com/inkarkat/vim-CursorLineCurrentWindow 60 | You can use your favorite plugin manager, or "git clone" into a directory used 61 | for Vim packages. Releases are on the "stable" branch, the latest unstable 62 | development snapshot on "master". 63 | 64 | This script is also packaged as a vimball. If you have the "gunzip" 65 | decompressor in your PATH, simply edit the \*.vmb.gz package in Vim; otherwise, 66 | decompress the archive first, e.g. using WinZip. Inside Vim, install by 67 | sourcing the vimball or via the :UseVimball command. 68 | 69 | vim CursorLineCurrentWindow*.vmb.gz 70 | :so % 71 | 72 | To uninstall, use the :RmVimball command. 73 | 74 | ### DEPENDENCIES 75 | 76 | - Requires Vim 7.0 or higher. 77 | 78 | CONFIGURATION 79 | ------------------------------------------------------------------------------ 80 | 81 | For a permanent configuration, put the following commands into your vimrc: 82 | 83 | By default, the plugin will localize any of 'cursorline', 'cursorcolumn', or 84 | 'wincolor' options, provided they are set during startup. To cover options 85 | that may be set on demand or to drop a set option, the List of option names 86 | can be overridden: 87 | 88 | let g:CursorLineCurrentWindow_OptionNames = ['cursorline'] 89 | 90 | CONTRIBUTING 91 | ------------------------------------------------------------------------------ 92 | 93 | Report any bugs, send patches, or suggest features via the issue tracker at 94 | https://github.com/inkarkat/vim-CursorLineCurrentWindow/issues or email 95 | (address below). 96 | 97 | HISTORY 98 | ------------------------------------------------------------------------------ 99 | 100 | ##### 2.00 RELEASEME 101 | - ENH: Generalize to also handle 'cursorcolumn' and non-flag window options 102 | like (new in Vim 8.1.1391) 'wincolor'. 103 | 104 | ##### 1.00 18-Aug-2012 105 | - First published version. 106 | 107 | ##### 0.10 23-Aug-2011 108 | - Allow persistent cursorlines via w:persistent\_cursorline. 109 | 110 | ##### 0.01 09-May-2006 111 | - Started development. 112 | 113 | ------------------------------------------------------------------------------ 114 | Copyright: (C) 2012-2019 Ingo Karkat - 115 | The [VIM LICENSE](http://vimdoc.sourceforge.net/htmldoc/uganda.html#license) applies to this plugin. 116 | 117 | Maintainer: Ingo Karkat <ingo@karkat.de> 118 | -------------------------------------------------------------------------------- /doc/CursorLineCurrentWindow.txt: -------------------------------------------------------------------------------- 1 | *CursorLineCurrentWindow.txt* Only highlight the screen line of the cursor in the currently active window. 2 | 3 | CURSOR LINE CURRENT WINDOW by Ingo Karkat 4 | *CursorLineCurrentWindow.vim* 5 | description |CursorLineCurrentWindow-description| 6 | usage |CursorLineCurrentWindow-usage| 7 | installation |CursorLineCurrentWindow-installation| 8 | configuration |CursorLineCurrentWindow-configuration| 9 | limitations |CursorLineCurrentWindow-limitations| 10 | known problems |CursorLineCurrentWindow-known-problems| 11 | todo |CursorLineCurrentWindow-todo| 12 | history |CursorLineCurrentWindow-history| 13 | 14 | ============================================================================== 15 | DESCRIPTION *CursorLineCurrentWindow-description* 16 | 17 | The 'cursorline' setting makes it easy to locate the cursor position. However, 18 | when there are split windows, each one shows its cursor line, and the only 19 | indication of the currently active window is the different 'statusline' 20 | highlighting (with |hl-StatusLine| vs. |hl-StatusLineNC|). 21 | 22 | This plugin avoids the clutter of multiple highlighted screen lines with split 23 | windows by disabling the 'cursorline', 'cursorcolumn', and/or 'wincolor' 24 | settings for all but the current window. Unlike a simplistic solution with a 25 | few autocmds, this plugin still allows for exceptions like disabling the 26 | cursorline for a particular window or making it permanent for (another) 27 | window. 28 | 29 | SEE ALSO * 30 | 31 | - The RelativeNumberCurrentWindow plugin (vimscript #4461) enables the 32 | 'relativenumber' setting only for the current window. 33 | 34 | RELATED WORKS * 35 | 36 | The basic idea is outlined in the Vim Tips Wiki: 37 | http://vim.wikia.com/wiki/Highlight_current_line 38 | - cursorline_current.vim (vimscript #5740) enables cursorline only in the 39 | current window and when not in insert mode. 40 | 41 | ============================================================================== 42 | USAGE *CursorLineCurrentWindow-usage* 43 | 44 | Globally enable 'cursorline', 'cursorcolumn' and/or 'wincolor' in your 45 | |vimrc|; e.g. > 46 | :set cursorline cursorcolumn 47 | After sourcing this plugin, the option(s) will only be active for the current 48 | window. So with multiple split windows, only one of them, the one where the 49 | cursor is in, will have 'cursorline' and 'cursorcolumn' enabled. 50 | 51 | 52 | Disable cursorline for the current window via: > 53 | :setlocal nocursorline 54 | This will persist even after moving away and back to the window. 55 | 56 | Disable cursorline globally via: > 57 | :set nocursorline 58 | As soon as you enter a window, its line highlighting will vanish. 59 | 60 | *w:persistent_cursorline* *w:persistent_cursorcolumn* *w:persistent_wincolor* 61 | For some kind of files it is helpful to keep the line highlighting active, 62 | e.g. to serve as a ruler. You can keep the highlighting for a particular 63 | window by setting a window-local variable: > 64 | :let w:persistent_cursorline = 1 65 | 66 | ============================================================================== 67 | INSTALLATION *CursorLineCurrentWindow-installation* 68 | 69 | The code is hosted in a Git repo at 70 | https://github.com/inkarkat/vim-CursorLineCurrentWindow 71 | You can use your favorite plugin manager, or "git clone" into a directory used 72 | for Vim |packages|. Releases are on the "stable" branch, the latest unstable 73 | development snapshot on "master". 74 | 75 | This script is also packaged as a |vimball|. If you have the "gunzip" 76 | decompressor in your PATH, simply edit the *.vmb.gz package in Vim; otherwise, 77 | decompress the archive first, e.g. using WinZip. Inside Vim, install by 78 | sourcing the vimball or via the |:UseVimball| command. > 79 | vim CursorLineCurrentWindow*.vmb.gz 80 | :so % 81 | To uninstall, use the |:RmVimball| command. 82 | 83 | DEPENDENCIES *CursorLineCurrentWindow-dependencies* 84 | 85 | - Requires Vim 7.0 or higher. 86 | 87 | ============================================================================== 88 | CONFIGURATION *CursorLineCurrentWindow-configuration* 89 | 90 | For a permanent configuration, put the following commands into your |vimrc|: 91 | *g:CursorLineCurrentWindow_OptionNames* 92 | By default, the plugin will localize any of 'cursorline', 'cursorcolumn', or 93 | 'wincolor' options, provided they are set during startup. To cover options 94 | that may be set on demand or to drop a set option, the List of option names 95 | can be overridden: > 96 | let g:CursorLineCurrentWindow_OptionNames = ['cursorline'] 97 | < 98 | ============================================================================== 99 | LIMITATIONS *CursorLineCurrentWindow-limitations* 100 | 101 | KNOWN PROBLEMS *CursorLineCurrentWindow-known-problems* 102 | 103 | TODO *CursorLineCurrentWindow-todo* 104 | 105 | IDEAS *CursorLineCurrentWindow-ideas* 106 | 107 | CONTRIBUTING *CursorLineCurrentWindow-contribute* 108 | 109 | Report any bugs, send patches, or suggest features via the issue tracker at 110 | https://github.com/inkarkat/vim-CursorLineCurrentWindow/issues or email 111 | (address below). 112 | 113 | ============================================================================== 114 | HISTORY *CursorLineCurrentWindow-history* 115 | 116 | 2.00 09-Feb-2020 117 | - ENH: Generalize to also handle 'cursorcolumn' and non-flag window options 118 | like (new in Vim 8.1.1391) 'wincolor'. 119 | 120 | 1.00 18-Aug-2012 121 | First published version. 122 | 123 | 0.10 23-Aug-2011 124 | Allow persistent cursorlines via w:persistent_cursorline. 125 | 126 | 0.01 09-May-2006 127 | Started development. 128 | 129 | ============================================================================== 130 | Copyright: (C) 2012-2020 Ingo Karkat 131 | The VIM LICENSE applies to this plugin; see |copyright|. 132 | 133 | Maintainer: Ingo Karkat 134 | ============================================================================== 135 | vim:tw=78:ts=8:ft=help:norl: 136 | -------------------------------------------------------------------------------- /plugin/CursorLineCurrentWindow.vim: -------------------------------------------------------------------------------- 1 | " CursorLineCurrentWindow.vim: Only highlight the screen line of the cursor in the currently active window. 2 | " 3 | " DEPENDENCIES: 4 | " - Requires Vim 7.0 or higher. 5 | " 6 | " Copyright: (C) 2012-2020 Ingo Karkat 7 | " The VIM LICENSE applies to this script; see ':help copyright'. 8 | " 9 | " Maintainer: Ingo Karkat 10 | 11 | " Avoid installing twice or when in unsupported Vim version. 12 | if exists('g:loaded_CursorLineCurrentWindow') || (v:version < 700) 13 | finish 14 | endif 15 | let g:loaded_CursorLineCurrentWindow = 1 16 | let s:save_cpo = &cpo 17 | set cpo&vim 18 | 19 | "- configuration --------------------------------------------------------------- 20 | 21 | if ! exists('g:CursorLineCurrentWindow_OptionNames') 22 | let g:CursorLineCurrentWindow_OptionNames = [] 23 | for s:optionName in ['cursorline', 'cursorcolumn'] + (exists('&wincolor') ? ['wincolor'] : []) 24 | execute 'if ! empty(&' . s:optionName . ') | call add(g:CursorLineCurrentWindow_OptionNames, "' . s:optionName . '") | endif' 25 | endfor 26 | endif 27 | 28 | 29 | "- functions ------------------------------------------------------------------- 30 | 31 | " Note: We use both global and local optionvalues to store the states, though 32 | " the option is window-local and only the local value effectively determines the 33 | " visibility of the highlighting. This makes for a better value inheritance when 34 | " splitting windows than a separate window-local variable would. 35 | 36 | function! s:Expand( template, optionName ) abort 37 | return substitute(a:template, '%s', a:optionName, 'g') 38 | endfunction 39 | function! s:CreateFunctionsForFlag( optionName ) abort 40 | execute s:Expand( 41 | \ 'function! s:OnEnter_%s()' . "\n" . 42 | \ ' if s:%s' . "\n" . 43 | \ ' if &g:%s || exists("w:persistent_%s") && w:persistent_%s' . "\n" . 44 | \ ' setlocal %s' . "\n" . 45 | \ ' else' . "\n" . 46 | \ ' setglobal %s' . "\n" . 47 | \ ' endif' . "\n" . 48 | \ ' else' . "\n" . 49 | \ ' setlocal no%s' . "\n" . 50 | \ ' endif' . "\n" . 51 | \ 'endfunction' . "\n" . 52 | \ '', a:optionName) 53 | execute s:Expand( 54 | \ 'function! s:OnLeave_%s()' . "\n" . 55 | \ ' if s:%s' . "\n" . 56 | \ ' if &l:%s' . "\n" . 57 | \ ' if ! &g:%s' . "\n" . 58 | \ ' " user did :setlocal %s' . "\n" . 59 | \ ' set %s' . "\n" . 60 | \ ' endif' . "\n" . 61 | \ ' else' . "\n" . 62 | \ ' if &g:%s' . "\n" . 63 | \ ' " user did :setlocal no%s' . "\n" . 64 | \ ' set no%s' . "\n" . 65 | \ ' else' . "\n" . 66 | \ ' " user did :set no%s' . "\n" . 67 | \ ' let s:%s = 0' . "\n" . 68 | \ ' endif' . "\n" . 69 | \ ' endif' . "\n" . 70 | \ ' if exists("w:persistent_%s") && w:persistent_%s' . "\n" . 71 | \ ' setglobal no%s' . "\n" . 72 | \ ' setlocal %s' . "\n" . 73 | \ ' else' . "\n" . 74 | \ ' setlocal no%s' . "\n" . 75 | \ ' endif' . "\n" . 76 | \ ' else' . "\n" . 77 | \ ' if &g:%s && &l:%s' . "\n" . 78 | \ ' " user did :set %s' . "\n" . 79 | \ ' let s:%s = 1' . "\n" . 80 | \ ' endif' . "\n" . 81 | \ ' endif' . "\n" . 82 | \ 'endfunction' . "\n" . 83 | \ '', a:optionName) 84 | endfunction 85 | function! s:CreateFunctionsForOptionValue( optionName ) abort 86 | execute s:Expand( 87 | \ 'function! s:OnEnter_%s()' . "\n" . 88 | \ ' if ! empty(s:%s)' . "\n" . 89 | \ ' if ! empty(&g:%s) || exists("w:persistent_%s") && w:persistent_%s' . "\n" . 90 | \ ' let &l:%s = s:%s' . "\n" . 91 | \ ' else' . "\n" . 92 | \ ' let &g:%s = s:%s' . "\n" . 93 | \ ' endif' . "\n" . 94 | \ ' else' . "\n" . 95 | \ ' setlocal %s=' . "\n" . 96 | \ ' endif' . "\n" . 97 | \ 'endfunction' . "\n" . 98 | \ '', a:optionName) 99 | execute s:Expand( 100 | \ 'function! s:OnLeave_%s()' . "\n" . 101 | \ ' if ! empty(s:%s)' . "\n" . 102 | \ ' if ! empty(&l:%s)' . "\n" . 103 | \ ' if empty(&g:%s)' . "\n" . 104 | \ ' " user did :setlocal %s=...' . "\n" . 105 | \ ' let &%s = &g:%s' . "\n" . 106 | \ ' endif' . "\n" . 107 | \ ' else' . "\n" . 108 | \ ' if ! empty(&g:%s)' . "\n" . 109 | \ ' " user did :setlocal %s=' . "\n" . 110 | \ ' set %s=' . "\n" . 111 | \ ' else' . "\n" . 112 | \ ' " user did :set %s=' . "\n" . 113 | \ ' let s:%s = ""' . "\n" . 114 | \ ' endif' . "\n" . 115 | \ ' endif' . "\n" . 116 | \ ' if exists("w:persistent_%s") && w:persistent_%s' . "\n" . 117 | \ ' setglobal %s=' . "\n" . 118 | \ ' let &l:%s = s:%s' . "\n" . 119 | \ ' else' . "\n" . 120 | \ ' setlocal %s=' . "\n" . 121 | \ ' endif' . "\n" . 122 | \ ' else' . "\n" . 123 | \ ' if ! empty(&g:%s) && ! empty(&l:%s)' . "\n" . 124 | \ ' " user did :set %s=...' . "\n" . 125 | \ ' let s:%s = &l:%s' . "\n" . 126 | \ ' endif' . "\n" . 127 | \ ' endif' . "\n" . 128 | \ 'endfunction' . "\n" . 129 | \ '', a:optionName) 130 | endfunction 131 | function! s:CreateFunctions( optionName ) abort 132 | execute 'let l:isFlag = (type(&' . s:optionName . ') == type(0))' 133 | if l:isFlag 134 | call s:CreateFunctionsForFlag(s:optionName) 135 | else 136 | call s:CreateFunctionsForOptionValue(s:optionName) 137 | endif 138 | endfunction 139 | function! s:Init( optionName ) abort 140 | execute s:Expand('let s:%s = &g:%s', a:optionName) 141 | endfunction 142 | function! s:CreateAutocommands( optionName ) abort 143 | augroup CursorLine 144 | execute s:Expand( 145 | \ ' autocmd VimEnter,WinEnter,BufWinEnter * call OnEnter_%s()' . 146 | \ '', a:optionName) 147 | execute s:Expand( 148 | \ ' autocmd WinLeave * call OnLeave_%s()' . 149 | \ '', a:optionName) 150 | augroup END 151 | endfunction 152 | 153 | augroup CursorLine 154 | autocmd! 155 | augroup END 156 | for s:optionName in g:CursorLineCurrentWindow_OptionNames 157 | call s:CreateFunctions(s:optionName) 158 | call s:Init(s:optionName) 159 | call s:CreateAutocommands(s:optionName) 160 | endfor 161 | unlet! s:optionName 162 | delfunction s:Expand 163 | delfunction s:CreateFunctionsForFlag 164 | delfunction s:CreateFunctionsForOptionValue 165 | delfunction s:CreateFunctions 166 | delfunction s:Init 167 | delfunction s:CreateAutocommands 168 | 169 | let &cpo = s:save_cpo 170 | unlet s:save_cpo 171 | " vim: set ts=8 sts=4 sw=4 noexpandtab ff=unix fdm=syntax : 172 | --------------------------------------------------------------------------------