From 72fd8ee3233f815f0795fb5c1f057aa8ad40a2bb Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 4 Aug 2018 18:59:09 +1200 Subject: Correct start-of-line jumps in Vim line exec maps g^ moves to the first non-blank character of the screen line, for use when 'wrap' is on. I just wanted ^. g_ is correct, though. --- vim/vimrc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'vim') diff --git a/vim/vimrc b/vim/vimrc index 445e0bbb..bb0e989f 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -324,11 +324,11 @@ nnoremap :enew " Execution mappings; each of these clobbers register z " \@ executes line in normal mode -nnoremap @ g^"zyg_@z +nnoremap @ ^"zyg_@z " \: executes line in command mode -nnoremap : g^"zyg_:z +nnoremap : ^"zyg_:z " \! executes line with 'shell' -nnoremap ! g^"zyg_:!z +nnoremap ! ^"zyg_:!z " If we're running NeoVim, source some extra configuration if has('nvim') -- cgit v1.2.3 From 705c61a9745d39f70e63f82e9d2004875192f87c Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 4 Aug 2018 19:03:19 +1200 Subject: Correct comments on Vim maps to show mappings The :map command does not show, for example, insert mode mappings. --- vim/vimrc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'vim') diff --git a/vim/vimrc b/vim/vimrc index bb0e989f..84195339 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -256,9 +256,9 @@ nnoremap j :buffers:buffer nnoremap k :marks " \l toggles showing tab, end-of-line, and trailing whitespace nnoremap l :setlocal list! list? -" \m shows all maps +" \m shows normal maps nnoremap m :map -" \M shows buffer-local maps +" \M shows buffer-local normal maps nnoremap M :map " \n toggles line numbers nnoremap n :setlocal number! number? -- cgit v1.2.3 From c4501004740d1a95fd7bf61aa4f19ff19a10eaec Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 4 Aug 2018 20:20:41 +1200 Subject: Add cursorline_current.vim plugin Also turn on 'cursorline' option in .vimrc, and update sahara.vim colorscheme, which has a nice subdued 'cursorline'. --- vim/bundle/sahara | 2 +- vim/plugin/cursorline_current.vim | 77 +++++++++++++++++++++++++++++++++++++++ vim/vimrc | 5 +++ 3 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 vim/plugin/cursorline_current.vim (limited to 'vim') diff --git a/vim/bundle/sahara b/vim/bundle/sahara index 6818d155..5b24c601 160000 --- a/vim/bundle/sahara +++ b/vim/bundle/sahara @@ -1 +1 @@ -Subproject commit 6818d1555a9d733f33f805e91b7147cdfddde048 +Subproject commit 5b24c60103d7ee056b88f1c0cc799d6479d75ece diff --git a/vim/plugin/cursorline_current.vim b/vim/plugin/cursorline_current.vim new file mode 100644 index 00000000..1ebf5821 --- /dev/null +++ b/vim/plugin/cursorline_current.vim @@ -0,0 +1,77 @@ +" +" 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') + 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 . 'windo 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 + if exists('##VimEnter') + autocmd VimEnter * call s:Load() + endif + + " Turn off 'cursorline' when leaving a window + if exists('##WinEnter') && exists('##WinLeave') + autocmd WinLeave * call s:Suspend() + autocmd WinEnter * call s:Restore() + endif + + " Turn off 'cursorline' when in insert mode + if exists('##InsertEnter') && exists('##InsertLeave') + autocmd InsertEnter * call s:Suspend() + autocmd InsertLeave * call s:Restore() + endif + +augroup END diff --git a/vim/vimrc b/vim/vimrc index 84195339..6b181fa7 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -61,6 +61,11 @@ set comments= " Give me a prompt instead of just rejecting risky :write, :saveas set confirm +" Only turn on 'cursorline' if my colorscheme loaded +if exists('g:colors_name') && g:colors_name ==# 'sahara' + set cursorline +endif + " Try to keep swapfiles in one system-appropriate dir set directory^=~/.vim/cache/swap//,~/vimfiles/cache/swap// -- cgit v1.2.3 From 382f066c7e2cf868c6160fd9a344926ba0c78d7e Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 4 Aug 2018 20:25:18 +1200 Subject: Require Vim 7 for cursorline_current.vim Most of the autocmd events are Vim 7, and there's a :for there too. --- vim/plugin/cursorline_current.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'vim') diff --git a/vim/plugin/cursorline_current.vim b/vim/plugin/cursorline_current.vim index 1ebf5821..a076bd97 100644 --- a/vim/plugin/cursorline_current.vim +++ b/vim/plugin/cursorline_current.vim @@ -9,7 +9,7 @@ if exists('g:loaded_cursorline_current') || &compatible finish endif -if !has('autocmd') || !has('windows') +if !has('autocmd') || !has('windows') || v:version < 700 finish endif let g:loaded_cursorline_current = 1 -- cgit v1.2.3 From 7bdd63e5b0268608108b345062a42783232b1a5d Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 4 Aug 2018 20:25:51 +1200 Subject: Remove illegal :wincmd range prefix Vim 7 doesn't allow a window prefix for :windo, so just break it into two steps instead. --- vim/plugin/cursorline_current.vim | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'vim') diff --git a/vim/plugin/cursorline_current.vim b/vim/plugin/cursorline_current.vim index a076bd97..d17fc769 100644 --- a/vim/plugin/cursorline_current.vim +++ b/vim/plugin/cursorline_current.vim @@ -44,7 +44,8 @@ function! s:Load() abort " 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 . 'windo call s:Suspend()' + execute l:wnum . 'wincmd w' + call s:Suspend() endif endfor -- cgit v1.2.3 From 80576742815e5374f4d097229b3ff7ff6a9dc6a5 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 4 Aug 2018 20:27:24 +1200 Subject: Remove conditionals for 'cursorline' hooks The version check for Vim 7 and the feature checks for +autocmd and +windows should be good enough. --- vim/plugin/cursorline_current.vim | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) (limited to 'vim') diff --git a/vim/plugin/cursorline_current.vim b/vim/plugin/cursorline_current.vim index d17fc769..1668b69a 100644 --- a/vim/plugin/cursorline_current.vim +++ b/vim/plugin/cursorline_current.vim @@ -56,23 +56,17 @@ endfunction " Set up hooks for toggling 'cursorline' augroup cursorline_current - autocmd! + autocmd! - " Turn off 'cursorline' for other windows on load - if exists('##VimEnter') - autocmd VimEnter * call s:Load() - endif + " Turn off 'cursorline' for other windows on load + autocmd VimEnter * call s:Load() - " Turn off 'cursorline' when leaving a window - if exists('##WinEnter') && exists('##WinLeave') - autocmd WinLeave * call s:Suspend() - autocmd WinEnter * call s:Restore() - endif + " Turn off 'cursorline' when leaving a window + autocmd WinLeave * call s:Suspend() + autocmd WinEnter * call s:Restore() - " Turn off 'cursorline' when in insert mode - if exists('##InsertEnter') && exists('##InsertLeave') - autocmd InsertEnter * call s:Suspend() - autocmd InsertLeave * call s:Restore() - endif + " Turn off 'cursorline' when in insert mode + autocmd InsertEnter * call s:Suspend() + autocmd InsertLeave * call s:Restore() augroup END -- cgit v1.2.3 From 4e9b3a3fa3febd61b13dd0a64ed6943fc5519961 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 4 Aug 2018 20:42:31 +1200 Subject: Make insert-mode cursorline ducking configurable --- vim/plugin/cursorline_current.vim | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'vim') diff --git a/vim/plugin/cursorline_current.vim b/vim/plugin/cursorline_current.vim index 1668b69a..a552fe95 100644 --- a/vim/plugin/cursorline_current.vim +++ b/vim/plugin/cursorline_current.vim @@ -66,7 +66,10 @@ augroup cursorline_current autocmd WinEnter * call s:Restore() " Turn off 'cursorline' when in insert mode - autocmd InsertEnter * call s:Suspend() - autocmd InsertLeave * call s:Restore() + " 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 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 --- vim/bundle/cursorline_current | 1 + vim/plugin/cursorline_current.vim | 75 --------------------------------------- 2 files changed, 1 insertion(+), 75 deletions(-) create mode 160000 vim/bundle/cursorline_current delete mode 100644 vim/plugin/cursorline_current.vim (limited to 'vim') 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 From cf01e7c310ef8f729bf055ac73f71ce33073ec1c Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 4 Aug 2018 21:11:24 +1200 Subject: Update cursorline_current.vim plugin to hotfix --- vim/bundle/cursorline_current | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'vim') diff --git a/vim/bundle/cursorline_current b/vim/bundle/cursorline_current index 9481bd3d..70eb3eaa 160000 --- a/vim/bundle/cursorline_current +++ b/vim/bundle/cursorline_current @@ -1 +1 @@ -Subproject commit 9481bd3d47f9cec47d08757e56a1942325ef989f +Subproject commit 70eb3eaaecfce486ce6df4a141d3d4d1bec30e0b -- cgit v1.2.3