sublime_text icon indicating copy to clipboard operation
sublime_text copied to clipboard

"word_wrap": true doesn't work

Open electroglyph opened this issue 5 months ago • 13 comments

Description of the bug

i have "word_wrap": true in settings, and word wrap isn't applied until manually do it from the menu

Steps to reproduce

open a big json file with 1 really long line

Expected behavior

word wrapping

Actual behavior

no word wrapping

Sublime Text build number

4200

Operating system & version

Windows 11

(Linux) Desktop environment and/or window manager

No response

Additional information

No response

OpenGL context information


electroglyph avatar Jul 12 '25 07:07 electroglyph

User settings in Preferences.sublime-settings can be overridden by settings in projects or syntax specific settings (see: https://www.sublimetext.com/docs/settings.html#settings-files).

To see the applied value,

  1. focus view with affected json file
  2. open ST's console
  3. run view.settings().get("word_wrap")

Unless word_wrap is not been applied with ST running in SAFE MODE, it is likely caused by such an overrding setting or a plugin.

deathaxe avatar Jul 12 '25 07:07 deathaxe

okay, it's definitely caused by loading JSON. i don't have any plugins installed, and i set JSON syntax settings to "word_wrap":true, and i used Everything to ensure there aren't any other settings file lurking...but the behavior is still the same.

view.settings().get("word_wrap") returns False with a JSON file open, but True otherwise

electroglyph avatar Jul 12 '25 09:07 electroglyph

view.settings().get("word_wrap") returns False with a JSON file open, but True otherwise

This just means anything is overriding your preferences. If you can rule out plugins, any setting is overriding your preferences - maybe Preferenses: Settings - Syntax Specific as a first step.

ST and bundled JSON syntax package don't specify an override for "word_wrap".

That's something on your setup. Beyond the list of settings priorities it's up to you to find the override.

FWIW, word_wrap is applied correctly to JSON on my end (ST3143 ... ST4200 / Windows 11).

deathaxe avatar Jul 12 '25 16:07 deathaxe

hmm, i thought i was running mostly default settings, but if it works on your end i'll close this. thanks for looking at it.

electroglyph avatar Jul 13 '25 00:07 electroglyph

the behavior depends on the size of the JSON file for some reason. so far the smallest I've found is about 3MB. JSON files that are that size and larger ignore the word_wrap setting. i've tested on linux and windows.

electroglyph avatar Jul 14 '25 11:07 electroglyph

Various features/functions are dynamically disabled by design, if certain sanity limits are exceeded.

deathaxe avatar Jul 14 '25 16:07 deathaxe

doesn't apply for .txt files tho, i can open 200MB .txt files and word_wrap stays enabled.

electroglyph avatar Jul 14 '25 20:07 electroglyph

Likely there is the answer - over a certain size, syntax highlighting isn't applied, therefore syntax specific settings are not applied

keith-hall avatar Jul 14 '25 20:07 keith-hall

Not sure if it helps but you could play with the "syntax_detection_size_limit": setting in the preferences or maybe even in syntax specific settings.

themilkman avatar Jul 15 '25 05:07 themilkman

Syntax highlighting and word wrapping is applied to 11MB JSON files on my Win11 box with ST4200 in SAFE MODE. A 33MB file opens in plain text, but word wrapping is also applied after manually setting syntax to JSON.

I haven't found evidence for ST to disable word_wrapping on those files.

I however found view.settings().get("word_wrap") returning False with same JSON files on my normal ST instance, even though word_wrap is set to auto in user preferences and not being overridden anywhere else.

After running view.settings().erase("word_wrap") via console, everything went back to normal. As file was opened fresh and setting isn't set False since then, I however have no idea how ST got into that state of individual view specific setting for JSON being set.

deathaxe avatar Jul 15 '25 17:07 deathaxe

If you file exceeds 2¹⁷ characters per line on average we disable word wrap. This is due to performance issues on long lines.

BenjaminSchaaf avatar Jul 16 '25 02:07 BenjaminSchaaf

This explains my observation as my json file was initially minified.

deathaxe avatar Jul 16 '25 06:07 deathaxe

Same problem, trying to open a fairly ok minified JSON and want to word-wrap it upon opening but not working, sounds it need somehow format the JSON into manageable line size and then trigger word-wrap upon open a new file

And I vide coded some simple solution of above to use PrettyJson to format first and apply word_wrap and working good for me (using Mac)

import sublime
import sublime_plugin

class AutoFormatJsonOnReadListener(sublime_plugin.EventListener):
    def on_load_async(self, view):
        # Check if this is a JSON file
        if view.match_selector(0, "source.json") or view.file_name() and view.file_name().endswith('.json'):
            # First, run pretty JSON formatting
            view.run_command("pretty_json")
            # Then enable word wrap
            view.settings().set("word_wrap", True)
    
    def on_new_async(self, view):
        # Also handle new files that are set to JSON syntax
        if view.match_selector(0, "source.json"):
            view.settings().set("word_wrap", True)

pinkfloyda avatar Aug 23 '25 16:08 pinkfloyda