vim:aucmd: Clear highlights on exiting visual mode

When exiting visual mode I want to clear the highlights of the visual
selection. As this is done automatically now, <Esc> does not need to do
it (and i had problems with keys.vim executing ClearHighlights because
of the script variables).

This reverts commit b3f1a469db ("vim:keys: Clear highlights on
normal-mode Esc").
This commit is contained in:
2024-03-24 16:35:49 +01:00
parent bfccb0f089
commit 6260c84f3a
2 changed files with 12 additions and 5 deletions

View File

@@ -1,7 +1,7 @@
" vim: set foldmethod=marker:
" Keybindings """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Clear all kinds of highlights when pressing Escape in normal mode
nnoremap <silent> <Esc> :nohlsearch <bar> call ClearHighlights()<CR><Esc>
" Clear search result highlights when pressing Escape in normal mode
nnoremap <silent> <Esc> :nohlsearch<CR><Esc>
" Indentation jump
" https://vim.fandom.com/wiki/Move_to_next/previous_line_with_same_indentation

View File

@@ -1,4 +1,10 @@
" Autocommands """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Bitfield for highlight_current augroup
const s:CLEAR_HIGHS_CWORD = 1
const s:CLEAR_HIGHS_VISUAL = 2
const s:CLEAR_HIGHS_ALL = 3
" Terminal
if (has('nvim'))
" Disable spellcheck
@@ -52,13 +58,13 @@ augroup termdebug_bindings
augroup END
" Highlight word under cursor
function! ClearHighlights()
if exists('w:cword_match_id')
function! ClearHighlights(what = s:CLEAR_HIGHS_ALL)
if and(a:what, s:CLEAR_HIGHS_CWORD) && exists('w:cword_match_id')
call matchdelete(w:cword_match_id)
unlet w:cword_match_id
unlet w:old_cword
endif
if exists('w:visual_match_ids')
if and(a:what, s:CLEAR_HIGHS_VISUAL) && exists('w:visual_match_ids')
for l:pairs in w:visual_match_ids
let l:id = l:pairs[0]
let l:win = l:pairs[1]
@@ -117,6 +123,7 @@ augroup highlight_current
\ endif
au CursorMovedI * call HighlightCurrentWord()
au WinLeave * call ClearHighlights()
au ModeChanged [vV\x16]*:* call ClearHighlights(s:CLEAR_HIGHS_VISUAL)
augroup END
" When switching focus to another window, keep the cursor location underlined.