Vim Highlight Trailing Whitespace AND Spaces Before and After Tabs

3.1k views Asked by At

I got this from the vim wiki and added it to my .vimrc to highlight trailing whitespace, and spaces before tabs (only when in insert mode):

highlight ExtraWhitespace guibg=purple
match ExtraWhitespace /\s\+$\| \+\ze\t/
autocmd BufWinEnter * match ExtraWhitespace /\s\+$\| \+\ze\t/
autocmd InsertEnter * match ExtraWhitespace /\s\+$%#\@<!$\| \+\ze\t/
autocmd InsertLeave * match ExtraWhitespace /\s\+$\| \+\ze\t/
autocmd BufWinLeave * call clearmatches()

I would like to extend this to include spaces after tabs.

So, I would like to:

  1. Highlight all trailing whitespace.
  2. Highlight spaces before, and after tabs.
  3. Don't highlight trailing whitespace while I am typing.

How can I do this?

1

There are 1 answers

0
ThePosey On

Since you didn't mention it at all have you tried using listchars? I have this in my .vimrc it doesn't highlight them but you can pick any special characters you want to show for them:

set listchars=eol:$,tab:>-,trail:ยท,extends:>,precedes:<