Sublime Forum

Line wrapping in Markdown files

#1

I’m new here, and I’m trying to make the switch from VS Code to Sublime Text. I’m not a developer, but I regularly work with thousands of Markdown files.

It seems I’m doing something wrong:

Line wrapping in Markdown files doesn’t work correctly with (at least) the following characters: `()[]*

For example:

What’s strange is that " doesn’t seem to be affected.

I’m not seeing that weird line wrapping in VS Code:

Visual_Studio_Code

What am I doing wrong?

0 Likes

#2

That’s a known ST issue.


1 Like

#3

Oh no, there’s an 11-year-old bug report for this issue. :frowning:

I was about to buy a license for Sublime Text, but now I’m having second thoughts.

Is there a (technical) reason why this bug is still there?

0 Likes

#4

Most likely reason might be it not neccessarily being a bug in common sense, because brackets are word separators, which do not have any special association with preceding or following text.

It is a syntax specific convention for them to start and belong to links in Markdown, thus expecting them to be wrapped together with whole link.

As a general purpose text/code editor ST however implements common syntax agnostic functions/behavior, which may not fullfill all expectations of every single syntax perfectly well.

Hence those tickets are labled “enhancement”, requesting some sort of functionality to maybe improve heuristics or add some sort of configuration to adapt behavior for certain syntaxes.

1 Like

#5

I’m surprised that an editor that is also advertised as being usable for prose (“The sophisticated text editor for code, markup and prose”) has such an issue. I haven’t experienced something like that at all with other text editors, and I’ve tried a bunch (Atom, VS Code, Notepad++, etc.).

I thought long and hard about this topic and still decided to buy a license for Sublime Text. Consider my payment a vote for fixing this issue–a vote with my wallet.

It doesn’t have to be fixed right now, but I would prefer if it took at most a couple of years, and not decades, to fix this issue. :slight_smile:

I want to move away from VS Code as Microsoft is steering the project in the wrong direction IMHO. For example, since last year, VS Code has looked even more like a web browser, since the underlying Electron framework incorporated the latest UI design from Google’s Chromium project, and Microsoft doesn’t care to fix this issue.

Is there maybe a plugin that can change the wrapping style? Or can someone write such a plugin?

0 Likes

#6

I rely on Wrap Plus for hard wrapping (alt+Q), but soft line wrapping is not customizable via plugins or metafiles/settings.

0 Likes

#7

For markdown I strongly suggest using dprint CLI tool (https://dprint.dev/), and possibly write a plugin which executes it on save. It will automatically wrap lines and also enforce formatting for all your .md files, so they are consistent.

Dprint config (.dprint.jsonc):

{
    "markdown": {
        "lineWidth": 79,
        "textWrap": "always",
    },
    "excludes": [
        "**/*-lock.json",
    ],
    "plugins": [
        "https://plugins.dprint.dev/markdown-0.18.0.wasm",
    ],
}

Install:

curl -fsSL https://dprint.dev/install.sh | sh

Execute:

dprint fmt yourfile.md

Format all your code base:

dprint fmt

You can wrap dprint in a simple plugin to execute it on save. Not tested:

import sublime_plugin, subprocess

class RunFixersOnSave(sublime_plugin.EventListener):
    def on_post_save(self, view):
        subprocess.call(["dprint", "fmt", view.file_name()])

I’m not a developer, but I regularly work with thousands of Markdown files.

In this case I think you could also benefit from LSP-marksman (gives you things like go-to definition) and LSP-cspell plugins (highlights spelling errors). You can install them via Package Control.

0 Likes