From 2027e12283784d6c419a0d9e60aaf1fb0eb024a2 Mon Sep 17 00:00:00 2001 From: Julian Prein Date: Sun, 28 Aug 2022 15:43:59 +0200 Subject: [PATCH] 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. --- .config/vim/vimrc.d/80-autocommands.vim | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.config/vim/vimrc.d/80-autocommands.vim b/.config/vim/vimrc.d/80-autocommands.vim index d167466..e2aead5 100644 --- a/.config/vim/vimrc.d/80-autocommands.vim +++ b/.config/vim/vimrc.d/80-autocommands.vim @@ -52,8 +52,13 @@ augroup termdebug_bindings augroup END " Highlight word under cursor +function! HighlightCurrentWord() + if (expand('') != '') + exec 'match CursorColumn /\V\<' . escape(expand(''), '/\') . '\>/' + endif +endfunction augroup highlight_current_word au! - au CursorHold * :exec 'match CursorColumn /\V\<' . escape(expand(''), '/\') . '\>/' - au CursorMoved * :exec 'match' + au CursorHold * call HighlightCurrentWord() + au CursorMoved * match augroup END