Reputation: 2978
I know there have been a number of questions that ask for hard wrapping in Sublime Text 3 and I've tried AutoWrap extension but when writing LaTeX code it would be best if it behaved like soft wrapping (i.e. reflow the paragraph if you delete words in the middle of the paragraph) while inserting hard wraps at say 100 characters. This matters because one would like to type as if in a wordprocessor but it's hard to find errors scanning a whole paragraph.
I understand this would be difficult because you would need to distinguish 'real' hard wraps from ones that should be reflowed (maybe one could use linefeed characters or something) but is there any package that does this kind of thing already? If not is this something that's even plausibly possible to implement using the plugin API?
Again, plugins that simply do automatic hard wraps or changing soft-wrap settings don't do what's needed. To be precise I've expanded the requirements at an absurd level of detail below but it can be summarized super easily.
I want the text editor to act just as it does now with respect to hard and soft wraps except: 1) Soft wraps increment the line number. 2) When saved to disk the soft wraps are saved as hard wraps for purposes of the tex compiler but when loaded by sublime text are recognized as needing to be treated as soft wraps.
Yes, this would be trivial if there were never any explicit hard wraps that need to be preserved and not subject to being reflowed when I change a line length.
Only read past this point if you really can't figure out what I'm asking for (which is surely my fault not yours).
Suppose I want wrapping at ~80chars and I write the following content (where the brackets represent some number of words of the given total length).
[70 chars] [10 chars] [11 chars] [60chars] [10chars] [9chars] [30chars]
This needs to automatically change to
[70 chars] [10 chars]\n
[11 chars] [60chars]\n
[10chars] [9chars] [30chars]\n
So far that's what AutoWrap does. But now I decide that the first [10 char] segment was just repeating something I'd said before so I move my cursor up to that line and delete only those 10 chars without touching lines 2 and 3. I need this to automatically reflow to without selecting the region of text I need reflowed. In other words pretend the hard wraps were soft wraps.
[70 chars] [11 chars]\n
[60chars] [10chars] [9chars]\n
[30chars]\n
However, if I'd originally typed an explicit return after the first 80 chars then I'd need that to be treated as a hard wrap so I'd instead just get
[70 chars]\n
[11 chars] [60chars]\n
[10chars] [9chars] [30chars]\n
If I deleted those 10 chars.
Upvotes: 4
Views: 1028
Reputation: 13970
There are already some Sublime Text packages that do what you want:
In addition to those packages there are lots of other wrap packages that may be of interest to you.
Just in case you don't know, Sublime Text can be told to soft wrap at whatever column width you want with the wrap_width
setting. This can be set as a global setting, a syntax setting, a project setting, or on a per view
basis.
The latter can be set by running the following command in the console, which as an example wraps at column 100. A value of 0 will tell Sublime Text to automatically wrap at the window width. Clearly the command could be easily modified and assigned to a key binding or command palette entry.
view.run_command("set_setting", { "setting": "wrap_width", "value": 100 })
Upvotes: 1