Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Is the buffer's indentation consistent and does it conform to tab settings?
VimL

Version 1.45

- Minor: Highlight action checks are dependent on 'iskeyword' setting, and could cause script errors.
- Add dependency to ingo-library (vimscript #4433). *** You need to separately install ingo-library (vimscript #4433) version 1.019 (or higher)! ***
latest commit e50606c709
Ingo Karkat authored committed
Failed to load latest commit information.
autoload Version 1.45
doc Version 1.45
plugin Version 1.44
README Version 1.45

README

This is a mirror of http://www.vim.org/scripts/script.php?script_id=1690

DESCRIPTION
In order to achieve consistent indentation, you need to agree on the
indentation width (e.g. 2, 4 or 8 spaces), and the indentation method (only
tabs, only spaces, or a mix of tabs and spaces that minimizes the number of
spaces and is called 'softtabstop' in Vim). Unfortunately, different people
use different editors and cannot agree on "the right" width and method.
Consistency is important, though, to make the text look the same in different
editors and on printouts. If any editor inadvertently converts tabs and
spaces, version control and diff'ing will be much harder to do.

The IndentConsistencyCop examines the indent of the buffer and analyzes the
used indent widths and methods. If there are conflicting ones or if bad
combinations of tabs and spaces are found, it alerts you and offers help in
locating the offenders - just like a friendly policeman:

    :IndentConsistencyCop
   Found inconsistent indentation in this buffer; generated from these
    conflicting settings:
    - tabstop (1838 of 3711 lines) <- buffer setting
    - 4 spaces (33 of 3711 lines)
    - bad mix of spaces and tabs (4 of 3711 lines)
        [I]gnore, (H)ighlight wrong indents...: h
    What kind of inconsistent indents do you want to highlight?
        Not [b]uffer settings (sts4), Not best (g)uess (tab), Not (c)hosen
        setting..., (I)llegal indents only: g
    Marked 180 incorrect lines.

If the buffer contents are okay, the IndentConsistencyCop can evaluate whether
Vim's buffer settings are compatible with the indent used in the buffer. The
friendly cop offers to correct your buffer settings if you run the risk of
screwing up the indent consistency with your wrong buffer settings:

    :IndentConsistencyCop
   The buffer's indent settings are inconsistent with the used indent '8
    spaces'; these settings must be changed:
    - expandtab from 0 to 1
    How do you want to deal with the inconsistency?
        [I]gnore, (C)hange: c
    The buffer settings have been changed: tabstop=8 softtabstop=0 shiftwidth=8
    expandtab

The IndentConsistencyCop is only concerned with the amount of whitespace from
column 1 to the first visible character; it does not check the alignment of
tables, equals signs in variable assignments, etc. Neither does it know any
specifics about programming languages, or your personal preferred indentation
style.

RELATED WORKS
- IndentConsistencyCopAutoCmds (vimscript #1691) complements this plugin. It
  automatically triggers the IndentConsistencyCop for certain filetypes when
  loading the buffer and optionally also on each write
- Indent Finder (vimscript #513) is a Python script and Vim plugin that scans
  any loaded buffer and configures the appropriate indent settings
- yaifa.vim (vimscript #3096) is a port to vimscript of the above
- detectindent.vim (https://github.com/ciaranm/detectindent) by Ciaran
  McCreesh tries to auto-detect the indentation settings
- GuessIndent (vimscript #4251) is based on detectindent.vim
- indentdetect.vim
  (https://github.com/ervandew/vimfiles/blob/master/vim/plugin/indentdetect.vim)
  by Eric Van Dewoestine performs a simple detection and can set defaults
  based on the filespec
- matchindent.vim (vimscript #4066) detects tabs, 2 and 4-space indents and
  adapts the indent settings accordingly
- sleuth.vim (vimscript #4375) by Tim Pope automatically adjusts 'shiftwidth'
  and 'tabstop' heuristically (via a simplistic sampling that does not check
  for bad or inconsistent indents) or by looking at other files of the same
  type
- filetype (vimscript #5065) highlights tabs when 'expandtab' is set, trailing
  spaces, and lines longer than 'textwidth', but doesn't actually check
  conformance to indent

USAGE
Start the examination of the current buffer or range via:
    :[range]IndentConsistencyCop
The triggering can be done automatically for configurable filetypes with the
autocmds defined in IndentConsistencyCopAutoCmds.vim (vimscript #1691).

If you chose to highlight incorrect indents, either re-execute the
IndentConsistencyCop to update the highlighting, or execute
    :IndentConsistencyCopOff
to remove the highlightings.

If you just want to check a read-only file, or do not intend to modify the
file, you don't care if Vim's buffer settings are compatible with the used
indent. In this case, you can use
    :[range]IndentRangeConsistencyCop
instead of :IndentConsistencyCop.
Something went wrong with that request. Please try again.