I would like to have a nice and sweet display of trailing white-space in my terminal vim. This would allow me to remove them before closing the file.
I am aware that this question is quite popular and I already found dozens of answers on SO. Unfortunately I did not found a satisfying one yet...
So I will try to summarize the gathered information and the solutions I found.
Solution 1: Manually highlight trailing spaces
highlight ExtraWhitespace ctermbg=red guibg=red
match ExtraWhitespace /\s\+$/
autocmd BufWinEnter * match ExtraWhitespace /\s\+$/
autocmd InsertEnter * match ExtraWhitespace /\s\+\%#\@<!$/
autocmd InsertLeave * match ExtraWhitespace /\s\+$/
autocmd BufWinLeave * call clearmatches()
Pros:
- Easy to use
- Fast
- Compatible with
cursorline
Cons:
- Chosen color not compatible with other color schemes because color is manually set to
red
- Big red background blocks are not very esthetic
Solution 2: Using list feature
set list
set listchars+=trail:◦
Pros:
- Easy to use
- Fast
Cons:
- Issue if
:set cursorline
enabled - Dedicated color for
list/trail
is not configurable. Has to be the same as the other listchars
Solution 3: Using conceal feature
syn match WhiteSpace "\s\+$" containedin=ALL conceal cchar=◦
set conceallevel=2
set concealcursor=nv
highlight Conceal ctermfg=red
Pros:
- Prettier than the first solution
Cons:
- Background is not the same as the cursorline background
- May interfere with other conceal rules
- Chosen color not always compatible with the color scheme
- Not compatible with older version of Vim
My question
Which one of the enumerated solutions is the most suitable in terms of performance and compatibility and how can I get all the pros and none of the cons?
In other terms, I would like to find a solution where:
- The highlight trailing color agree with the chosen colorscheme
- This color is clearly visible but not too aggressive to the eyes
- Compatible with
cursorline
(background and foreground)`- Compatible with other plugins that may use conceal
- The trailing char can be set to any Unicode char
:hi link ExtraWhitespace CursorLine
. See:help hi-link
.