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?
:au BufEnter *.js :set shiftwidth=2
. This works for all projects,*.*
is just a pattern. You can use filename or path as well. Or, you can use similar auto command like what I gave, for each file. You can instruct the auto command to take the tabwidth of current file and put it for path of this file. Its pretty easy.