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)
This commit is contained in:
@@ -40,3 +40,13 @@ if (get(g:, 'loaded_fzf'))
|
|||||||
" Use a theme for bat in the preview that somewhat resembles onedark
|
" Use a theme for bat in the preview that somewhat resembles onedark
|
||||||
let $BAT_THEME='TwoDark'
|
let $BAT_THEME='TwoDark'
|
||||||
endif
|
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\+\%#\@<!$')
|
||||||
|
augroup END
|
||||||
|
|||||||
@@ -1,19 +1,4 @@
|
|||||||
" Autocommands """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
" Autocommands """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||||
" Highlight trailing whitespaces
|
|
||||||
" (https://vim.fandom.com/wiki/Highlight_unwanted_spaces)
|
|
||||||
" Create highlight group
|
|
||||||
highlight ExtraWhitespace ctermbg=red guibg=red
|
|
||||||
" Associate with patter (trailing whitespaces)
|
|
||||||
match ExtraWhitespace /\s\+$/
|
|
||||||
" apply not only to the first window
|
|
||||||
autocmd BufWinEnter * match ExtraWhitespace /\s\+$/
|
|
||||||
" Do not match when typing at the end of a line
|
|
||||||
autocmd InsertEnter * match ExtraWhitespace /\s\+\%#\@<!$/
|
|
||||||
" Reset when leaving insert mode
|
|
||||||
autocmd InsertLeave * match ExtraWhitespace /\s\+$/
|
|
||||||
" Clear all matches
|
|
||||||
autocmd BufWinLeave * call clearmatches()
|
|
||||||
|
|
||||||
" Terminal
|
" Terminal
|
||||||
if (has('nvim'))
|
if (has('nvim'))
|
||||||
" Disable spellcheck
|
" Disable spellcheck
|
||||||
|
|||||||
Reference in New Issue
Block a user