nano
has a useful bit of syntax highlighting that actually highlights whitespace (tabs and spaces), under two conditions: (1) the whitespace does not have a non-whitespace character between either the last character or the beginning of the line and it, and (2) that the file is source code and not plain, plain text (as in a shopping list). How can I emulate this kind of behavior in vim
?
How to enable nano-like whitespace highlighting in vim
vim
Best Answer
I use
set list
andset listchars
in.vimrc
to showtabs
and trailingwhite spaces
, you can use a condition for selective file type like this.So my files look like this when those charaters are present.
Note:
·
is not.
Edit
So to answer to your comment, you can do that by adding this to your
~/.vimrc
, make sure to add it after the colorscheme, or it will behi clear
'd.You can change the highlight colors and refine the regular expression as needed.
/\s\+$/
will match trailing spaces or tabs and lines that contain nothing but either of those 2 characters. If you only want to highlight lines with just tabs and spaces use/^\s\+$/
instead.