It's very easy to set a text editor to use spaces or tab characters with each press of the tab key. However, I'm working with a grip of Python code maintained by a large team of developers in my company, and some use spaces and some use tabs. I cannot simply make them all conform with each other, because 1) it would break git blame, 2) it would muddle git diff, and 3) it would inevitably break the build the next time another editor hits their tab key in one of the files.
Instead, I'd like a text editor that automatically determines whether a file is indented by spaces or tabs and then conforms to the existing layout. Does anybody know if something like this exists?
When the code is executed, the “TabError inconsistent use of tabs and spaces in indentation”. This occurs when the code has all the tabs and spaces mixed up. To fix this, you have to ensure that the code has even indentation. Another way to fix this error is by selecting the entire code by pressing Ctrl + A.
This is the Adaptive Formatting behavior in Visual Studio: the Editor heuristically determines if the current file should use Tabs or Spaces for indentation. To turn off this behavior, please go to Tools > Options, and then Text Editor > Advanced > Uncheck "Use adaptive formatting".
So, at the end of the day, tabs versus spaces is truly a matter of preference, however the tab is still the character specifically designed for indentation, and using one tab character per indentation level instead of 2 or 4 spaces will use less disk space / memory / compiler resources and the like.
Changing default indentation settingstranslateTabsToSpaces: set to either 'true' or 'false'. If true, then when tab is pressed, an equivalent number of spaces will be inserted into the buffer instead. Defaults to false. tabSize: controls the visual width of tabs.
How do I set tab space in Visual Studio? Click on 'Text Editor', then select 'C/C++' and open the 'Tabs' settings. Set both 'Tab size' and 'Indent size' to 4 and make sure 'Insert spaces' is selected below.
That's quite simple in Sublime. Just Ctrl+Shift+P (or Command+Shift+P on MacOS) to open the tools pallet, type reindent , and pick Indentation: Reindent Lines . It should reindent all the file you are in, just remember to save before running the command, or it may not appear.
Sublime Text does this.
I think geany ( http://www.geany.org/ ) has that option in the preferences, if you use linux.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With