Skip to content
Switch branches/tags

Latest commit

* Add option to limit number of other files checked, defaulting to 20.
* Add global and local options to disable automatic detection.
* Provide :Sleuth for manual detection.
* Add indicator for flagship.vim.
* Skip over Python style triple quoted strings.
* Skip over XML/HTML style comments.
* Skip over backtick quoted strings in Go files only.
* Avoid activating on help buffers.
* Check vimrc when sleuthing under Vim filetype.
* Disallow odd 'shiftwidth' values greater than 3.

Git stats


Failed to load latest commit information.
Latest commit message
Commit time


This plugin automatically adjusts 'shiftwidth' and 'expandtab' heuristically based on the current file, or, in the case the current file is new, blank, or otherwise insufficient, by looking at other files of the same type in the current and parent directories. In lieu of adjusting 'softtabstop', 'smarttab' is enabled.

Compare to DetectIndent. I wrote this because I wanted something fully automatic. My goal is that by installing this plugin, you can remove all indenting related configuration from your vimrc.


Install using your favorite package manager, or use Vim's built-in package support:

mkdir -p ~/.vim/pack/tpope/start
cd ~/.vim/pack/tpope/start
git clone
vim -u NONE -c "helptags sleuth/doc" -c q


  • Searching for other files of the same type continues up the directory hierarchy until a match is found. This means, for example, the indent for the first file in a brand new Ruby project might very well be derived from your .irbrc. I consider this a feature.
  • If your file is consistently indented with hard tabs, 'shiftwidth' will be set to your 'tabstop'. Otherwise, a 'tabstop' of 8 is enforced.
  • The algorithm is rolled from scratch, fairly simplistic, and only lightly battle tested. It's probably not (yet) as good as DetectIndent. Let me know what it fails on for you.


Like sleuth.vim? Follow the repository on GitHub and vote for it on And if you're feeling especially charitable, follow tpope on Twitter and GitHub.


Copyright © Tim Pope. Distributed under the same terms as Vim itself. See :help license.