Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Highlight tabs in vim when expandtab is set

Is there a recipe to make vim highlight tab characters with a given color, but only while the expandtab option is set? I know about 'listchars', but I'd like to be able to differentiate a "valid tab" from an "invalid tab".

like image 607
Mu Mind Avatar asked Oct 06 '22 01:10

Mu Mind


1 Answers

You can add a custom :match for tab characters based on :autocmds, like this:

autocmd WinEnter,VimEnter *
\   if &expandtab |
\       silent! call matchadd('Error', '\t',  10, 31337) |
\   else |
\       silent! call matchdelete(31337) |
\   endif

(For simplicity, this uses a hard-coded ID.)

Alternatively, you could use a plugin like my IndentConsistencyCop, which checks for both inconsistent indentation and mismatches of the buffer and its settings, and by default also highlights the wrong lines. (The plugin page has links to alternative plugins.)

like image 107
Ingo Karkat Avatar answered Oct 10 '22 02:10

Ingo Karkat