*heurindent.txt*  Heuristic indentation detection

Author:  Sven Karsten Greiner <https://www.sammyshp.de/>
Repo:    https://github.com/SammysHP/vim-heurindent
License: GPLv3

Inspired by Tim Pope's "Sleuth".

                                                *heurindent*
This plugin automatically adjusts 'shiftwidth' and 'expandtab' heuristically
based on the indentation of the current file.

In order to work correctly, 'tabstop' should be set to a sensible value
(usually you want 'tabstop' to be 8, unless you know what you do).

It is also recommended to set 'smarttab' so that a <Tab> uses 'shiftwidth'
for indentation (see also |i_Tab|).

This plugin is only available if 'compatible' is not set.

1. Commands                                     |heurindent-commands|
      :Heurindent[!]                            |:Heurindent|
      :HeurindentReset                          |:HeurindentReset|
      HeurindentIndicator()                     |HeurindentIndicator()|
2. Settings                                     |heurindent-settings|
      heurindent_automatic                      |g:heurindent_automatic|
      heurindent_maxlines                       |g:heurindent_maxlines|
      heurindent_min_sw                         |g:heurindent_min_sw|
      heurindent_max_sw                         |g:heurindent_max_sw|
      heurindent_weight_factor                  |g:heurindent_weight_factor|
      heurindent_ratio_threshold                |g:heurindent_ratio_threshold|
      heurindent_skip_comments                  |g:heurindent_skip_comments|
      heurindent_debug                          |g:heurindent_debug|


==============================================================================
1. Commands                                     *heurindent-commands*

                                                *:Heurindent*
:Heurindent[!]          Detect indentation. Usually this is done automatically
                        (see |g:heurindent_automatic|).
                        With ! same as |:HeurindentReset|.

                                                *:HeurindentReset*
:HeurindentReset        Reset shiftwidth and expandtab to the state before the
                        first invocation of |:Heurindent|.

                                                *HeurindentIndicator()*
HeurindentIndicator()   Indicator for inclusion in 'statusline'.


==============================================================================
2. Settings                                     *heurindent-settings*

All settings can be used in a global or a bufer local scope. If a setting has
no buffer local value, heurindent falls back to the global value (and then to
the built-in default).

                                                *g:heurindent_automatic*
Automatic detection of indentation can be disabled with: >
  let g:heurindent_automatic = 0
<
                                                *g:heurindent_maxlines*
The number of scanned lines can be set with: >
  let g:heurindent_maxlines = 1024
<
                                                *g:heurindent_min_sw*
                                                *g:heurindent_max_sw*
                                                *g:heurindent_weight_factor*
                                                *g:heurindent_ratio_threshold*
There are some variables available which can be used to tune the heuristic
algorithm.

|g:heurindent_min_sw| and |g:heurindent_max_sw| define the bounds in which
the algorithm tries to find the 'shiftwidth'. The values are constrained by
"min <= max" and "min > 0". By default min is 2 (i.e. ignore single space
indentation) and max is the current value of 'tabstop'.

The value of |g:heurindent_weight_factor| controls the decay of the period
weighting. The algorithm weights each period (e.g. 4, 8, 16...) a little less
so that the shortest, most often used period is found.

By default 'expandtab' is set if there are more soft tabs (indentations with
more than 'tabstop' spaces) than hard tabs. You can control this threshold by
setting |g:heurindent_ratio_threshold|. A value of 1 sets always noexpandtab
while a negative value sets always expandtab. A value of 0 sets noexpandtab
if there are only hard tabs.

                                                *g:heurindent_skip_comments*
Comments are not a reliable source of indentation information, especially
block comments. Thus block comments are skipped by default. The heuristic for
comment detection is not perfect, so you can disable skipping comments: >
  let g:heurindent_skip_comments = 0
<
Currently following types are detected: >
  /* C-style block comments */
  <!-- XML comments -->
  """ Python docstrings """
<
                                                *g:heurindent_debug*
If you are tuning the algorithm or if you are unsure about why it made a
specific decision, you can set >
  let g:heurindent_debug = 1
<to get some helpful verbosity of the algorithm.

 vim:tw=78:et:ft=help:norl:
