sponsor Vim development Vim logo Vim Book Ad

GuessIndent : Indentation guessing plugin

 script karma  Rating 0/0, Downloaded by 1220  Comments, bugs, improvements  Vim wiki

created by
Alex Ogier
 
script type
utility
 
description
GuessIndent Plugin
------------------

This plugin is based on the DetectIndent plugin by Ciaran McCreesh.
Many thanks to him for inspiration and code.

Source code and development is at https://github.com/ogier/guessindent

Usage:
------

    :GuessIndent

The :GuessIndent command tries to determine whether the active file
uses tabs or spaces for indentation as a convention. If the file
appers to use spaces for indentation, the plugin will try to
intelligently set the 'shiftwidth' and 'softtabstop' options.

You can run this command automatically every time a file is loaded.
To do that, include the following in your ~/.vimrc file:

    autocmd BufReadPost * :GuessIndent

Customizing:
------------

If at least 3/4 of the lines in the active file appear to use spaces
for indentation, then 'expandtab' will be set. If at least 3/4 of
the lines in the active file use tabs for indentation, 'noexpandtab'
will be set. If no tabs or spaces are used (for example if the file
is new) then the command does nothing. If there is a roughly even mix
then the file is considered to be ambiguous.

If the file sometimes uses spaces and sometimes uses tabs for
indentation ambiguously, spaces are arbitrarily chosen as the
indentation method and 'expandtab' is set. If you prefer to use
tabs in this case and set 'noexpandtab', include the following
in your ~/.vimrc file:

    let g:guessindent_prefer_tabs = 1

For performance reasons, :GuessIndent reads a limited number of
lines from the active file. The default is currently to read a
maximum of 1024 lines. To change this maximum, include the
following in your ~/.vimrc file:

    let g:guessindent_max_lines_to_analyse = 2048

License
-------

This plugin is distributed under the same terms as vim istelf.
Contributions are welcome.
 
install details
Unzip and install to ~/.vim/plugin and ~/.vim/doc. You may need to run :Helptags before you can see the documentation with :help GuessIndent.
 

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
guessindent-1.0.zip 1.0 2012-10-01 7.0 Alex Ogier Initial upload
ip used for rating: 142.132.191.50

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
   
Vim at Github