Sublime Forum

Word wrap 80 doesn't fit 80 characters

#1

My Markdown text file is set to word wrap by 80. Any text up to 79 characters fits into a line, for larger text soft returns are added. Why can i not fit 80 characters in a line?

0 Likes

#2

Are you using a monospace font? What version of Sublime Text are you using?

0 Likes

#3

my font is

view.settings().get('font_face')
'Monospace'

I changed wrapping from 80 to 10 for demonstration. My user settings are:

"font_size": 11,
"word_wrap": true,
"wrap_width": 10,

note that 10 character don’t fit in one line:

the default settings file state:

// Note that the font_face and font_size are overridden in the platform
// specific settings file, for example, “Preferences (Linux).sublime-settings”.
// Because of this, setting them here will have no effect: you must set them
// in your User File Preferences.

Preferences (Linux).sublime-settings does not exist.

I reverted Sublime Text to default state to make sure there is no plugin interferring. The screen recording uses my custom setup but the defaults show the same behaviour.

  • OS: Linux PopOS! 20.10
  • sublime.version(): ‘3211’
0 Likes

#4

It’s not a matter of font size, but the number of columns when soft wrapping applies.

See how a space after w causes the latter to be moved to the next line. The behavior is even inconsistent depending on whether space is added or removed.

{
    "word_wrap": true,
    "wrap_width": 10,
    "rulers":
    [
        10
    ],
}

Animation

ST 4098
Windows 10

1 Like

#5

I see that the algorithm searches the optimal wrapping at the right margin. My behaviour is different from yours - i can never fit 10 characters into one line; 0123456789 does not fit, no matter what! I find the behaviour on my machine unintuitive, but i acknowledge that different algorithm behave differently for word wrapping.

I am not an expert, i cannot tell if this is correct or not. I compare it with other text editors, bash terminal they fit 10 characters in a width of 10 but these are very crude comparisons :smiley:

Perhaps a different algorithm is used in ST4098, or maybe you are on Windows and it uses a different algorithm there, or maybe newline (\n, \n\r) are interferring (although i think i would have noticed if that was the case).

what i whished to have done is an ASCII with some text on the left and some on the right with 80 chars ruler, such that it causes no wrapping in any text editor set to 80 chars. So far it seems like i can achieve this with "wrap_width": 81 for my setup.

0 Likes

#6

it is a known issue:

the solution is to set wrap_width to value + 1, although it appears that ST 4098 has been fixed.

0 Likes