From 4415ff46538f613b3de18717e3eba38b3863c097 Mon Sep 17 00:00:00 2001 From: Julian Prein Date: Thu, 25 Aug 2022 03:21:34 +0200 Subject: [PATCH] vim: Fix broken highlight of trailing whitespaces Apply the following: 1. Switch to `matchadd` as `match` can only be used for **one** highlight 2. Use an autocommand group for better behaviour when reloading the vimrc. 3. Use just one pattern as it seems to work always. (Apparently `\%#` is not matched in normal mode) --- .config/vim/vimrc.d/50-aesthetics.vim | 10 ++++++++++ .config/vim/vimrc.d/80-autocommands.vim | 15 --------------- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/.config/vim/vimrc.d/50-aesthetics.vim b/.config/vim/vimrc.d/50-aesthetics.vim index 23ddc30..63d556b 100644 --- a/.config/vim/vimrc.d/50-aesthetics.vim +++ b/.config/vim/vimrc.d/50-aesthetics.vim @@ -40,3 +40,13 @@ if (get(g:, 'loaded_fzf')) " Use a theme for bat in the preview that somewhat resembles onedark let $BAT_THEME='TwoDark' endif + +" Highlight trailing whitespaces +" Pattern taken from https://vim.fandom.com/wiki/Highlight_unwanted_spaces +highlight TrailingWhitespace ctermbg=red guibg=red +augroup HighlightTrailingWhitespace + au! + " NOTE: VimEnter is necessary as well as WinNew is not triggered for the + " first window created after startup (see :help WinNew) + au VimEnter,WinNew * call matchadd("TrailingWhitespace", '\s\+\%#\@