detectindent


Ⅰ. 插件描述

Vim script for automatically detecting indent settings

Ⅱ. 基本信息

创建日期:  2009-07-14
使用用户:  18
Github星:  17
插件作者:  Rory O’Kane

Ⅲ. 安装方法

使用Vundle管理器安装

在你的.vimrc下添加:
Plugin 'roryokane/detectindent-you-belong-with-me'
… 然后在Vim中运行以下命令:
:source %
:PluginInstall

对于Vundle版本 < 0.10.2,请用上面的Bundle替换Plugin。

使用NeoBundle管理器安装

在你的.vimrc下添加:
NeoBundle 'roryokane/detectindent-you-belong-with-me'
… 然后在Vim中运行以下命令:
:source %
:NeoBundleInstall

使用VimPlug管理器安装

在你的.vimrc下添加:
Plug 'roryokane/detectindent-you-belong-with-me'
… 然后在Vim中运行以下命令:
:source %
:PlugInstall

使用Pathogen管理器安装

在终端中运行以下命令:
cd ~/.vim/bundle
git clone https://github.com/roryokane/detectindent

Ⅳ. 文档说明

# 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:

  • a full README for GitHub, with a description and installation instructions
  • automated tests of the plugin
  • require only a majority, not an entirety, of lines to use tabs for tabs to be selected
  • detect the indent width when tabs are detected, not only when spaces are detected
  • set -1 for softtabstop when Vim supports it, to make it easier for users to manually change indentation
  • remove the option g:detectindent_preferred_expandtab, which is redundant with the global setting &g:expandtab
  • gracefully exit on old Vim versions known to not work (< 7.0)
  • better wording of verbose log messages
  • various refactorings
  • style and formatting fixes in code and documentation

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.

添加新评论