vim:autocmd: Highlight visual selection
Highlight visual selection similar to the cword highlight. Restrict the cword highlight to only normal mode.
This commit is contained in:
@@ -52,16 +52,24 @@ augroup termdebug_bindings
|
|||||||
augroup END
|
augroup END
|
||||||
|
|
||||||
" Highlight word under cursor
|
" Highlight word under cursor
|
||||||
function! HighlightCurrentWord()
|
function! ClearHighlights()
|
||||||
if exists('w:old_cword') && w:old_cword == expand('<cword>')
|
|
||||||
" Do not delete and readd the match if on the same word
|
|
||||||
return
|
|
||||||
endif
|
|
||||||
if exists('w:cword_match_id')
|
if exists('w:cword_match_id')
|
||||||
call matchdelete(w:cword_match_id)
|
call matchdelete(w:cword_match_id)
|
||||||
unlet w:cword_match_id
|
unlet w:cword_match_id
|
||||||
unlet w:old_cword
|
unlet w:old_cword
|
||||||
endif
|
endif
|
||||||
|
if exists('w:visual_match_id')
|
||||||
|
call matchdelete(w:visual_match_id)
|
||||||
|
unlet w:visual_match_id
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! HighlightCurrentWord()
|
||||||
|
if exists('w:old_cword') && w:old_cword == expand('<cword>')
|
||||||
|
" Do not delete and readd the match if on the same word
|
||||||
|
return
|
||||||
|
endif
|
||||||
|
call ClearHighlights()
|
||||||
if (expand('<cword>') != '')
|
if (expand('<cword>') != '')
|
||||||
let w:old_cword = expand('<cword>')
|
let w:old_cword = expand('<cword>')
|
||||||
let w:cword_match_id = matchadd(
|
let w:cword_match_id = matchadd(
|
||||||
@@ -70,9 +78,29 @@ function! HighlightCurrentWord()
|
|||||||
\ -1)
|
\ -1)
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! HighlightVisualSel()
|
||||||
|
call ClearHighlights()
|
||||||
|
|
||||||
|
let l:old_reg = getreg('"')
|
||||||
|
let l:old_regtype = getregtype('"')
|
||||||
|
norm ygv
|
||||||
|
|
||||||
|
let w:visual_match_id = matchadd(
|
||||||
|
\ 'CursorColumn',
|
||||||
|
\ '\V' . escape(@", '\'),
|
||||||
|
\ -1)
|
||||||
|
|
||||||
|
call setreg('"', l:old_reg, l:old_regtype)
|
||||||
|
endfunction
|
||||||
|
|
||||||
augroup highlight_current_word
|
augroup highlight_current_word
|
||||||
au!
|
au!
|
||||||
au CursorMoved * call HighlightCurrentWord()
|
au CursorMoved * if mode() == 'n' |
|
||||||
|
\ call HighlightCurrentWord() |
|
||||||
|
\ else |
|
||||||
|
\ call HighlightVisualSel() |
|
||||||
|
\ endif
|
||||||
au CursorMovedI * call HighlightCurrentWord()
|
au CursorMovedI * call HighlightCurrentWord()
|
||||||
augroup END
|
augroup END
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user