1

I'm looking for a way that will highlight lines (or part of lines) that don't adhere to current tabs settings.

Say for instance, I have the following configuration in my .vimrc

tabstop=8 
softtabstop=8 
shiftwidth=8 
noexpandtab

Is it possible to highlight lines that don't adhere to the above settings ?

0
2

My IndentConsistencyCop plugin checks the consistency of the used indent, and compares this with the buffer's indent settings. With a companion plugin, it can be triggered automatically for configured filetypes. (The plugin page has links to alternative plugins.)

2
  • Just tested you plugin. it failed with errors: Error detected while processing function IndentConsistencyCop#IndentConsistencyCop..<SNR>139_IndentBufferInconsistencyCop: line 19: E117: Unknown function: ingo#query#ConfirmAsText E15: Invalid expression: ingo#query#ConfirmAsText(a:inconsistentIndentationMessage, ['&Ignore', '&Highlight wrong indents...'], 1, 'Question') ... – stdcall Sep 12 '16 at 16:48
  • 1
    You also need to install ingo-library (vim.org/scripts/script.php?script_id=4433); it contains general-purpose functions used by all of my plugins. – Ingo Karkat Sep 13 '16 at 8:10
0

With those settings, a "line that doesn't adhere to current tabs settings" is basically "a line with spaces as indentation".

You can highlight such lines by searching:

/\v^\t* +\t*[^\s]

Broken down:

  • \v − "very magic" mode so we don't have to use too many \ later (see :help /\v)
  • ^ − anchor to the start of the line.
  • \t* − match zero or more tab characters.
  • + − match one or more space characters.
  • \t* − match zero or more tab characters again.
  • [^\s] − match anything except a space character.

Or if you want to highlight the entire line, add .* to the end to also match the rest of the line:

/\v^\t* +\t*[^\s].*

If you don't want to clobber your search history with this, you can use :match:

:match Error /\v^\t* +\t*[^\s].*/

See :help :match.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.