Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a text editor that will automatically determine whether to indent with spaces or tabs? [closed]

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?

like image 595
Cory Petosky Avatar asked Nov 09 '09 21:11

Cory Petosky


People also ask

How do you resolve inconsistent use of tabs and spaces in indentation?

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.

Does Visual Studio use tabs or spaces?

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

Are tabs or spaces the preferred method for indentation?

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.

What are the indentation options available in the sublime text editor?

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 change the tab spacing or code?

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.

How do I check indentations in Sublime Text?

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.


2 Answers

Sublime Text does this.

like image 120
Michael Hackner Avatar answered Nov 14 '22 23:11

Michael Hackner


I think geany ( http://www.geany.org/ ) has that option in the preferences, if you use linux.

like image 30
senicar Avatar answered Nov 15 '22 00:11

senicar