Reputation: 446
I've been using a syntax highlight for some time to match space characters that come after leading tabs.
autocmd Syntax * highlight LeadingSpaces guibg=#afd7af ctermbg=Black
autocmd Syntax * syntax match LeadingSpaces /^\t\+\zs \+/
Problem is, it doesn't always work. For example, inside block comments the highlight doesn't take effect:
test // the extra space before "test" gets highlighted
/**
* test // here the extra spaces aren't highlighted
*/
If anybody has an idea what I'm doing wrong, that would be great. Otherwise I'll have to go back to regular matching, I guess.
Upvotes: 1
Views: 97
Reputation: 22596
I had a similar problem (but display trailing spaces at the end of the line). To solve it, instead of using syntax, which interferes with the actual syntax you can just highlight a regular expression using matchadd
.
This look like this (reusing your LeadingSpaces )
autocmd BufNew * call matchadd ('LeadingSpaces', '^\t\+\zs \+')
Upvotes: 2