From 5ee98950eb40bfe76decea3cba93135d02b1ef90 Mon Sep 17 00:00:00 2001 From: Julian Prein Date: Tue, 6 Dec 2022 15:31:53 +0100 Subject: [PATCH] vim:autocmd: Check if same cword when highlighting When highlighting the current word, check if it is the same as the currently highlighted one, so that matchdelete and matchadd are not called unnecessarily. --- .config/vim/vimrc.d/80-autocommands.vim | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.config/vim/vimrc.d/80-autocommands.vim b/.config/vim/vimrc.d/80-autocommands.vim index 66121f3..af29e5c 100644 --- a/.config/vim/vimrc.d/80-autocommands.vim +++ b/.config/vim/vimrc.d/80-autocommands.vim @@ -53,11 +53,16 @@ augroup END " Highlight word under cursor function! HighlightCurrentWord() + if exists('w:old_cword') && w:old_cword == expand('') + " Do not delete and readd the match if on the same word + return + endif if exists('w:cword_match_id') call matchdelete(w:cword_match_id) unlet w:cword_match_id endif if (expand('') != '') + let w:old_cword = expand('') let w:cword_match_id = matchadd( \ 'CursorColumn', \ '\V\<' . escape(expand(''), '/\') . '\>',