vim:aucmd: Highlight selection on linewise v-mode

I assumed that the selection will always be one character long when the
ModeChanged event is triggered. This is not the case when entering
linewise visual mode.

Fixes: b0688da69e ("vim:aucmd: Do not highlight selection on
       ModeChanged")
TODO: There are more ways of triggering ModeChanged to visual mode with
      a selection of more than one character (e.g. `[count]v`).
This commit is contained in:
2024-10-28 21:09:28 +01:00
parent c011f2ed6a
commit c608700199
Notes: Julian Prein 2025-06-30 14:06:03 +02:00
`gv` is another way of entering visual mode with a multi-char selection.

View File

@@ -173,11 +173,12 @@ augroup highlight_current
au CursorMovedI * call HighlightCurrentWord()
au WinLeave * call ClearHighlights()
au ModeChanged [vV\x16]*:* call ClearHighlights(s:CLEAR_HIGHS_VISUAL) | call HighlightCurrentWord()
" NOTE: HighlightVisualSel is not called here as I rarely need one-character
" highlighting and I can work around by moving back and forth once.
" TODO: are there situation where ModeChanged is triggered and the selection
" is immediately longer than one char without triggering CursorMoved?
au ModeChanged *:[vV\x16]* call ClearHighlights(s:CLEAR_HIGHS_CWORD)
" NOTE: HighlightVisualSel is not called when entering non-linewise visual
" mode as I rarely need one-character highlighting and I can work
" around by moving back and forth once.
" TODO: Fix for other ways of entering with a longer selection
au ModeChanged *:[v\x16]* call ClearHighlights(s:CLEAR_HIGHS_CWORD)
au ModeChanged *:V call ClearHighlights(s:CLEAR_HIGHS_CWORD) | call HighlightVisualSel()
augroup END
" When switching focus to another window, keep the cursor location underlined.