Sublime Forum

Sublime tab space messed up in windows notepad

#1

basicly I use sublime text2 and .txt format to make some note when reading, and I use tab to align some table like text, but after I save it and reopen it in windows notepad, the alignment just messed up, I searched a little and found this: http://www.opensourcehacker.com/2012/05/13/never-use-hard-tabs/, it basicly say to use space as indent instead of tab, but I thought that not a proper sollution, so is there other way to let the tab alignment looks all alike in all other editor, like a plugin or something? thx.

0 Likes

#2

Roughly 50% of programmers prefer hard tabs, so you can find an equal number of never-use-spaces-for-tabs links. With a good editor, it makes no difference at all what you choose. In Sublime, for instance, just click the Tab Size button in the status bar to pick what you want.

Anyway, when using hard tabs, there are two - and only two - simple rules:

  1. Press TAB for indentation

  2. Press SPACE for extra alignment

Then your code will look great in all editors, no matter what tab width they have set.

It requires that you write code alignment-friendly, so you write:

void somefunc(
         int param,
         int param2)
{
}

which is easier to read anyway, instead of the borked:

void somefunc(int param,
           int param2)
{
}

So learn the difference between indentation and alignment, and hard-tabs are easy peasy.

0 Likes

#3

The difference in rendering between ST and notepad is very likely caused by the size of TAB.
The TAB is only 1 char, the editor display it like t was replacing by a series of spaces.
Notepad has a fixed value of 8 spaces per TAB (historical), ST (and most editors) have an option to choose this number.
Take a look at the View -> Indentation menu in ST, you will find this option and another to tell ST to use spaces or tab when you hit TAB key.
If you set your TAB size to 8 in ST, the file will be rendering the same in notepad.

0 Likes