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.
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 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!