vim:autocmd: Match current word only if it exists

Check that the current word under the cursor exists (not empty) before
adding it as match.

Fix the disappearing of the welcome screen after a short time when
opening vim without file as argument.
This commit is contained in:
2022-08-28 15:43:59 +02:00
parent 947a939f67
commit 2027e12283

View File

@@ -52,8 +52,13 @@ augroup termdebug_bindings
augroup END
" Highlight word under cursor
function! HighlightCurrentWord()
if (expand('<cword>') != '')
exec 'match CursorColumn /\V\<' . escape(expand('<cword>'), '/\') . '\>/'
endif
endfunction
augroup highlight_current_word
au!
au CursorHold * :exec 'match CursorColumn /\V\<' . escape(expand('<cword>'), '/\') . '\>/'
au CursorMoved * :exec 'match'
au CursorHold * call HighlightCurrentWord()
au CursorMoved * match
augroup END