Sublime Forum

Spacing visually totally wrong

#1

Hello,

I am a new user of Sublime Text. And although I like the editor, there are a few things missing. That said, my primary problem right now is that spacing seems to be totally off visually. I changed the user settings to use 2 spaces for indenting (instead of the usual 4).

Now when I code something in python like:

testcode = dict(test_variable1='some random quote',
                test_variable2='another random quote')

it looks visually in the editor like:

testcode = dict(test_variable1='some random quote',
           test_variable2='another random quote')

Note the indenting is visually totally wrong: test_variable2 and dict seem to be aligned, however both test_variable1 and test_variable2 start at position 17 of each line. So although the spacing is accurate, it looks like it is not.

Same for the ruler I added. I would like to have a ruler at 80 characters so I always know when I am getting to the end of my line (I try to code everything within 80 characters). However, if I set the ruler to position 80 it looks visually more than 160 spaces. Only if I set the ruler value to 39 it comes closest to 80 characters for a majority of all lines, but just a slight majority and not all sentences.

In all my previous editors I have used (of which Geany was the my trusted sidekick for the last 4 years) setting rulers at the 80 character mark was never a problem. And also visually showing the spacing right was not either. This is causing me a lot of headache and a lot of manual code fixing.

Any ideas how I can fix this?

Thanks

0 Likes

#2

Are you using a fixed-width font?

0 Likes

#3

Hello Adzenith,

I am using the default that came with the installation. I did not set any in particular. Is there any you can recommend?

Thanks,

0 Likes

#4

Personally I use Consolas, which comes with Windows or Microsoft Office, but any fixed-width font will do.
The important thing is just that all the letters have the same width—otherwise, if you’re using a proportional font, Sublime Text will measure everything based off of the width of a space (I believe) which is generally pretty thin. This would explain why your rulers are so far in.
It may be that you have some interesting setup and you’re missing the font that Sublime Text looks for by default, and it’s falling back to a proportional font.

0 Likes

#5

Hello adzenith,

Thanks a million, that seems to have solved the problem. I changed the font_face to “Droid Sans Mono” and all spacing seems to be correct now.

For future reference (if anyone else runs into this thread), the following links may be useful:
http://en.wikipedia.org/wiki/Monospaced_font
http://en.wikipedia.org/wiki/Samples_of_monospaced_typefaces
http://www.codeproject.com/Articles/30040/Font-Survey-42-of-the-Best-Monospaced-Programming

Thanks again!

0 Likes

#6

ST2 has always had indentation issues in Python, and it’s nothing to do with fonts. For example:

[code]

ST2

some_func(arg1,
arg2)

PEP8

some_func(arg1,
arg2)[/code]

# ST2
some_list = [item1,
item2]

# PEP8
some_list = [item1,
             item2]

And so on. Not even edge cases. These are quite common.

EDIT: Speaking of PEP8, does anyone use autopep8? Could it be used as a workaround for indentation issues?

EDIT2: Ok, installed autopep8, and the Ctrl+Shift+8 binding can fix the poorly indented lines. Works on whole file if there’s no selection, or on selected lines.

0 Likes