55

I work on a range of JavaScript projects. In most of these projects, the indentation of JavaScript files is 2 spaces, so I've set my default indentation width to that. However it becomes 1 or 4 in some other projects.

Is there a way to ask Vim to change the indentation style based on the style already used in the current file?

thameera
  • 17,434
  • 16
  • 40
  • 42

2 Answers2

48

Install this plugin: tpope/vim-sleuth

Dhruva Sagar
  • 5,510
  • 2
  • 22
  • 17
18

ciaranm/detectindent might be what you're looking for. It's unmaintained (last updated in 2015, there was also a fork that was last updated in 2016: roryokane/detectindent) and I haven't used it, but looks like it does what you want:

A Vim plugin, for automatically detecting indent settings. This plugin adds a :DetectIndent command, which tries to intelligently set the 'shiftwidth', 'expandtab' and 'tabstop' options based upon the existing settings in use in the active file.