Showing trailing spaces in vim

2019-03-09 05:15发布

问题:

I've set the following options in .vimrc

set listchars=tab:▸\ ,trail:·
set list

And expected to see dots in those places where spaces are used for tabulation in the code (I use spaces, not tabs). However, the result is different:

Could you please recommend how to reach the desired result? Thanks!

回答1:

You should check this link. I'm using the match command solution :

:highlight ExtraWhitespace ctermbg=red guibg=red
:match ExtraWhitespace /\s\+$/

This page also provides list based solutions which I haven't personally tried.



回答2:

And expected to see dots in those places where spaces are used for tabulation in the code (I use spaces, not tabs)

Actually this is the other way round, tab option is used to display a character when a tab character is inserted (\t) instead of spaces. And trail is use to show trailing spaces at the end of lines.

You seem to have single empty line with trailing spaces, and dots are correctly displayed.

If you are only using spaces tab option is not used or displayed.



回答3:

The vim-better-whitespace plugin incorporates many tips from the Vim Wiki page referenced in @icecrime's answer. It also has some nifty configuration options.

I installed pathogen.vim just to use this plugin and am happy with my life, all things considered.