Home Download Buy Blog Forum Support

Sublime tab space messed up in windows notepad

Sublime tab space messed up in windows notepad

Postby Unopoo on Sun Jun 22, 2014 3:26 pm

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.
Unopoo
 
Posts: 7
Joined: Wed Jun 04, 2014 4:10 pm

Re: Sublime tab space messed up in windows notepad

Postby fixtix on Mon Jun 23, 2014 9:02 am

Unopoo wrote: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.


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:

Code: Select all
void somefunc(
         int param,
         int param2)
{
}


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

Code: Select all
void somefunc(int param,
           int param2)
{
}


So learn the difference between indentation and alignment, and hard-tabs are easy peasy.
fixtix
 
Posts: 1
Joined: Mon Jun 23, 2014 8:57 am

Re: Sublime tab space messed up in windows notepad

Postby bizoo on Mon Jun 23, 2014 1:38 pm

Unopoo wrote: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

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.
bizoo
 
Posts: 883
Joined: Wed Dec 08, 2010 6:53 am
Location: Switzerland


Return to Technical Support

Who is online

Users browsing this forum: Exabot [Bot] and 34 guests