vim: Make trailing space highlighting more subtle
I sometimes work in files where I cannot remove trailing whitespaces (at least not permanently). In these cases the background highlighting of them is quite strong and can be a bit annoying. To make this more pleasing, use the foreground to highlight trailing characters, as long as tabs and trailing spaces are displayed as non-space characters. For this I also set `trail` in `&listchars`, and while at it, merged the two lines setting `&listchars` and cleaned up some comments.
This commit is contained in:
@@ -77,11 +77,11 @@ if (has('cmdline_info'))
|
|||||||
endif
|
endif
|
||||||
" Show whitespace characters
|
" Show whitespace characters
|
||||||
set list
|
set list
|
||||||
set listchars=tab:>·
|
" Display tabs and trailing space characters as well an indicator for long lines
|
||||||
|
" when not wrapping
|
||||||
|
set listchars=tab:>·,trail:·,extends:>
|
||||||
" Wrap lines
|
" Wrap lines
|
||||||
set wrap
|
set wrap
|
||||||
" When wrap is off, show a visual indicator that the lines continues
|
|
||||||
set listchars+=extends:>
|
|
||||||
" Keep current line away from top/bottom borders of the buffer when scrolling
|
" Keep current line away from top/bottom borders of the buffer when scrolling
|
||||||
set scrolloff=5
|
set scrolloff=5
|
||||||
" Enable mouse
|
" Enable mouse
|
||||||
|
|||||||
@@ -46,12 +46,21 @@ if (get(g:, 'loaded_fzf'))
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
" Highlight trailing whitespaces
|
" Highlight trailing whitespaces
|
||||||
" Pattern taken from https://vim.fandom.com/wiki/Highlight_unwanted_spaces
|
if match(&listchars, 'trail: \@!') > -1 && match(&listchars, '\vtab:( +)@!') > -1
|
||||||
highlight TrailingWhitespace ctermbg=red guibg=red
|
" Use foreground for coloring if tabs and trailing spaces are displayed
|
||||||
|
" as non-space characters
|
||||||
|
highlight TrailingWhitespace ctermfg=red guifg=red
|
||||||
|
else
|
||||||
|
" Background otherwise
|
||||||
|
highlight TrailingWhitespace ctermbg=red guibg=red
|
||||||
|
endif
|
||||||
augroup HighlightTrailingWhitespace
|
augroup HighlightTrailingWhitespace
|
||||||
au!
|
au!
|
||||||
" NOTE: VimEnter is necessary as well as WinNew is not triggered for the
|
" Pattern taken from
|
||||||
" first window created after startup (see :help WinNew)
|
" https://vim.fandom.com/wiki/Highlight_unwanted_spaces
|
||||||
|
"
|
||||||
|
" NOTE: VimEnter is necessary as well, since WinNew is not triggered for
|
||||||
|
" the first window created after startup (see :help WinNew)
|
||||||
au VimEnter,WinNew * call matchadd("TrailingWhitespace", '\s\+\%#\@<!$')
|
au VimEnter,WinNew * call matchadd("TrailingWhitespace", '\s\+\%#\@<!$')
|
||||||
augroup END
|
augroup END
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user