At my workplace, we have a large codebase, some of which dates back decades, which is edited using text editors like Vim, Emacs, and our in-house text editor, all of which insert mixed tabs and spaces in their default configurations. These files show up in Sublime with incorrect indentation:
This occurs because, in files with mixed tabs, tabs always align to multiples of 8 characters. However, in Sublime, tabs always align according to the indentation size used to nest blocks. It's possible to configure Sublime to display these files correctly, by setting the "Tab Size" setting to 8 and disabling "Indent Using Spaces", but at the expense of essential editing conveniences:
Enter almost always indents the new line incorrectly, adding a tab after unnecessary spaces (see screenshot below).
Ctrl+[ and Ctrl+] increase or decrease indentation by 2 or 4 levels instead of a single level, depending on whether the "logical" indent size for the file is 4 or 2 spaces.
- "Indent Using Spaces" must be off, or else copying and pasting replaces all tab characters with spaces, creating unnecessary noise in diffs. Modific's "Revert Modified Part" action should revert all changes but unless this option is turned off, it also replaces Tabs with spaces.
At my workplace, it's considered important not to introduce spurious space changes so that blame tools work properly, and because large diffs are harder to inspect and review. Since only a few of us use Sublime, we don't have the organizational capital to change every single file in our very large codebase to use spaces instead of tabs, and to prompt every engineer in the organization to configure their own text editor to avoid mixing spaces and Tabs in existing files and new files. Instead, I carefully inspect every file before committing it to make sure I didn't introduce spurious space changes, and I work around the limitations of Sublime every time I insert a new line or change the indentation of a line. Obviously, whenever possible, I make sure to use only spaces for indentation in new files.
What is needed is an option to set the "logical" indent size and a separate option to set the "physical" size of tab characters, and appropriate handling by the indenting subroutines in Sublime. Another option can be added which determines whether new lines and indentation changes should use mixed tabs by default (which can be determined automatically by inspecting the file). This is what is done in Vim and Emacs, for example.
I have used Sublime for several years and still consider it the best text editor available, which is why I bought licenses for both versions 2 and 3. However, this issue costs me time daily and causes me to seriously consider other options periodically. Especially in large organizations, I imagine many other engineers find themselves in the same situation. I hope this detailed report encourages and aids the developers to fix Sublime's handling of mixed spaces and tabs.