Rewrap text
Check for existing issues
- [X] Completed
Describe the feature
I would like "rewrap" functionality for Zed. Here is a VS Code plugin that does it: https://github.com/stkb/Rewrap -- with screenshots for those who aren't familiar.
Synonyms include:
- reflow text
- manual wrapping
Related
- https://github.com/zed-industries/zed/issues/4588
If applicable, add mockups / screenshots to help present your vision of the feature
No response
I'd be happy to work on it, seems like something I'd use pretty often. There's some questions I have about it.
- Does it have to respect every language formatters settings? For example, if there's a
rustfmt.tomlorruff.tomlfile specifying the line length, does it have to respect that? - Also in the case where there is a global default set in the
settings.jsonfile does it take precedence over any folder specific settings? (I'm assuming this one will probably be no, since we'd like folder specific settings to be higher priority) - Is there a preferred keymapping that we'd like for this? I know zed tries to stick as close to vscode keymaps as possible with the defaults.
That's all I can think of right now but if there's anything else please let me know, in the meantime I'm going to go dig around the codebase, see if I can figure this out!
Edit: Had a poke around the codebase and ran it locally, as far as I can tell the rewrap text will just be another editor action that will go in crates/editor/src/actions.rs and then adding the implementation in editor.rs in the same crate.
Sidenote -- how are people wrapping comments without using Rewrap? Once I started using it, I couldn't go back to doing it manually!
Does it have to respect every language formatters settings? For example, if there's a
rustfmt.tomlorruff.tomlfile specifying the line length, does it have to respect that?
In VSCode, there are per-project settings, and I know Rewrap respects that at least. I haven't tested which other config files it Rewrap supports.
Regardless of Rewrap's behavior, I think respecting all the per-language project settings might be a lot of work for a project at Zed's stage -- there are many languages! Consider prioritizing these three config files:
- VSCode per-project settings, because VSCode is popular.
- EditorConfig, because the project aims to be language-agnostic (even though it doesn't appear to be super popular).
- Prettier, because it's popular and sort of language-agnostic. (Prettier is technically language-agnostic but in practice has ended up only having first-class support for frontend-land languages.)
- See also https://github.com/prettier/prettier/issues/265 -- a ticket to add Rewrap functionality into Prettier itself, I think this would be ideal.
Also in the case where there is a global default set in the
settings.jsonfile does it take precedence over any folder specific settings? (I'm assuming this one will probably be no, since we'd like folder specific settings to be higher priority)
The folder one should definitely take priority. This is how VSCode does it and it seems to have worked well; I've never seen issues with this prioritization in practice.
Is there a preferred keymapping that we'd like for this? I know zed tries to stick as close to vscode keymaps as possible with the defaults.
The Rewrap one is Alt-Q. But I have no idea why they chose Q, I wonder if the author of the plugin just wanted to find a corner key because it's convenient. If this is true, then I have a suspicion that this is a shortcut that can commonly conflict with other extensions' shortcuts.
I'm not OP but at least for me, I wouldn't mind key combo was changed, as long as there is a key combo for it. I'm thinking Alt-R for Rewrap, Alt-W for reWrap, or Alt-J because its effect in practice is actually very similar to the "join lines" feature. (If you have soft wrap enabled, join lines basically makes a set of hard-wrapped lines respect the soft wrap guide. Rewrap does the same thing too, except by inserting hard breaks.)
Okay I've been super busy the last couple of weeks since I've just been dealing with crisis after crisis, but I'm working on it now If anyone would like to pair program and work on it together please let me know! I find I get a lot more done when pairing
- EditorConfig, because the project aims to be language-agnostic (even though it doesn't appear to be super popular).
Should zed-industries/zed#5599 be reopened for this? EditorConfig is very standardized across ecosystems (Prettier respects it for example) and (except rewrapping) maps cleanly to existing Zed options.
Is anybody on this? It's an awesome feature that I miss greatly from VSCode—I daresay I could never go back.
The Rewrap one is Alt-Q. But I have no idea why they chose Q, I wonder if the author of the plugin just wanted to find a corner key because it's convenient. If this is true, then I have a suspicion that this is a shortcut that can commonly conflict with other extensions' shortcuts.
M-Q (Alt-Q) is the Emacs shortcut for this feature: https://www.gnu.org/software/emacs/manual/html_node/emacs/Fill-Commands.html
I'd really love to see this feature being built-in to Zed!
I totally agree with @szhu above – I can't imagine wrapping Markdown manually after I started using Rewrap (which seems to be, unfortunately, not maintained anymore).
Seems to have been implemented in Zed's main branch, scheduled to be in stable next week:
- https://x.com/zeddotdev/status/1836468422017691853
- https://github.com/zed-industries/zed/pull/17909
- https://github.com/zed-industries/zed/pull/17953
Today I got Zed Preview 0.154.0 which has the 'rewrap' command. 🎸
Yep! This will be in stable next Wednesday, as a core editor command, so I'm going to close this issue out!