roryokane / detectindent

Vim script for automatically detecting indent settings
21 stars 6 forks source link
editor-plugin indent indentation vim

DetectIndent

A Vim plugin for automatically detecting indent settings

This script provides a command which will attempt to guess the correct indent settings for an open file, for use when there is no modeline available. Specifically, the command sets the following buffer-local options for you:

Note that this is a pure Vim implementation, and doesn’t require any external applications or interpreters.

Usage

:DetectIndent

May also be used in an autocommand. For example, you might want to put this in your vimrc:

augroup DetectIndent
   autocmd!
   autocmd BufReadPost *  DetectIndent
augroup END

Options

The plugin provides some options you can set to configure what settings are chosen in edge cases or to constrain the range of indent widths allowed. Read about these options in the docs on GitHub or with :help detectindent in Vim.

Installation

With pathogen.vim:

cd ~/.vim/bundle
git clone https://github.com/roryokane/detectindent.git

With Vundle:

Bundle 'roryokane/detectindent'

About this fork

The original plugin (the one in the official Vim plugin repository) seems to be abandoned. So this is a fork of Raymond Ko’s version, which was the most polished and complete of the forks at that time, and included some merged commits that gave this plugin much more robust detection of indentation style than the original. His README said this:

I merged all the forks that I found were semi-reasonable in the GitHub network graph. This was done in less than 15 minutes, so expect bugs!

My fork’s additions to Raymond’s fork:

Feel free to submit pull requests or file issues, such as if DetectIndent wrongly guesses the indentation of a file you tried to edit in Vim.