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".
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.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With