What is the option that makes Sublime Text add whitespace at the left of wrapped lines?

Solution 1:

Well, that was fun. There's no easily accessible setting for this. But as you indicate, ST decides whether to add an extra indent when soft wrapping, from whether the syntax is considered code-like or plain text-like.

Being one or the other is up to the package defining the syntax to specify. So lacking a global setting from ST, you need to change your text packages. As an example, let's take Text. That contains Plain text.tmLanguage. In that you change

<key>scopeName</key>
<string>text.plain</string>

to

<key>scopeName</key>
<string>source.plain</string>

I'm unsure of whether there'll be ill effects from not keeping .plain.

One easy way to do this is to get the PackageResourceViewerpackage.

After install, do:

  • cmdshiftp
  • Type: Open Resource
  • return
  • Type: Text
  • return
  • Type: Plain text.tmLanguage
  • Make your edit and save.

PackageResourceViewer will save the modified Text package to your Packages directory. And sublime will display files considered to have Plain text-syntax, like they are code.

The caveat is that you need to do this for every text-syntax you want to be considered code.

Solution 2:

As @AdamAL said, it's dependent on both the 'indent_subsequent_lines' setting as well as whether it's considered a "source" or a "text" language ... by default, "markup" languages (such as HTML, CSS, etc.) and plain text, etc., are considered "text", and programming languages such as C++, Java, PHP, etc., are considered "source".

"Source" languages will indent subsequent soft-wrapped lines (if the indent_subsequent_lines is true), whereas "text" languages will only indent up to the same level as the current line.

For each one you want to change, you'll need to edit the settings of the given language. @AdamAL's answer provides a great way to do this using the PackageResourceViewer package:

After install, do:

[Ctrl/Cmd]+[shift]+p, "Open Resource"

Find the name of the language you want to change, and find either the .sublime-syntax file or the .tmLanguage file. .sublime-syntax is supported from build 3084 of ST 3 and appears that it may trump values in the .tmLanguage file in supported versions, if present (when editing the definition of TaskPaper files provided by the "PlainTasks" package, my change didn't take when just editing the PlainTasks.tmLanguage, I had to edit the PlainTasks.sublime-syntax before it took).

In .sublime-syntax (which are YAML files) look for the first scope: line, where the main scope name of the language is identified (there will be lots of other scope: entries further down under contexts:).

In .tmLanguage (which are XML .plist files) look for the <string> following the <key>scopeName</key>.

Sublime Text Syntax Definition Documentation Reference:

scopeName

Name of the topmost scope for this syntax definition. Either source.<lang> or text.<lang>. Use source for programming languages and text for markup and everything else.

The <lang> (without brackets) is just an identifier string for the given syntax/language definition.

I noted that it seems that (in ST 3, anyway), no restart of Sublime Text is needed to get the changes to apply, if the edit is in the right place.

And also note that there may be other effects of changing this in more complex packages -- For example, in PlainTasks, the additional keybindings that it defines depended on it looking for a context that included text.todo, which I changed to source.todo in several places. So in order for the keybindings to work properly again, I also had to update my .sublime-keymap for that package. (This could also be because I changed it in a place besides the .sublime-syntax that I didn't need to. Just sayin' -- YMMV.)