I work on different projects that have preferences for tabs and others for spaces. Is there a way to toggle using tabs or spaces for indentation? I tried a function I saw online function TabToggle() but it did not work. Any help would be great.


2 Answers 2


Generally the retab command and the expandtab option can accomplish what you're talking about without plugins if that's what you want. Do :set expandtab to set vim to prefer spaces to tabs, :set noexpandtab to prefer tabs to spaces. Use :retab! to switch a whole file to whichever you've set. This has caveats, and I recommend :help :retab and :help 'expandtab' for more information, and of course a plugin as already suggested will probably be more robust, but those settings are a quick-and-dirty way to get it done.

  • I like the use of this and can set mappings to this. The editorconfig works well but would probably prefer to stay with this option than having to rely on another plugin.
    – pertrai1
    Apr 12, 2016 at 17:36

I highly recommend editorconfig.

Putting a very simple .editorconfig at the root of your project will make every IDE/editor with an editorconfig plugin automatically comply to the rules laid out in that config file. It's truly beautiful! No more mixed indentation!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.