-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Command to hard-wrap selected text. #625
Comments
A tree sitter based text object for comments would help here, and I was thinking of adding other objects too (functions, classes, etc). |
Is that necessary? If we can keep the code relatively self-contained without bringing in too many other APIs, I think that would be preferable. Scanning for blocks of commented lines isn't much work, and we'll need to do scanning anyway to detect e.g. indentation level, paragraph breaks denoted by blank commented lines, etc. I can see possibly wanting to use tree sitter for multi-line comments (e.g. I guess if someone has something like this: /*
* A multi-line comment where
* leading asterisks are used
* to make things prettier.
*/ It might be helpful just for identifying the commented area, but then re-wrapping that as the user probably intends is a whole 'nother can of worms anyway, and I don't know if we want the feature to get that deep in the weeds, with heuristics for all the fancy ways people might format their comments. |
I was talking about a generic text object for comments that will simply select it and then you can copy, delete, change, etc. I was imagining the hard wrapping command to work on selections, so selecting the comment and then re-wrapping it was the workflow I was comparing it to. But since we have the comment character for each language it should be easy to rewrap all the comments in the file for consecutive single line comments, which is what I think you meant ? |
The flow I had in vim was to make a selection then press Q (should be a different key here since we'll use that for macros) to wrap all the lines in the selection. It's comment aware so that if lines begin with the comment token it'll properly wrap them (prefix new lines with comment tokens). Should be fairly easy to do with the existing commenting functions (there's one that can detect line comments) Text objects: I do want to have these for functions, comments etc ( |
Ah, got it. I thought you were talking about how we would implement this feature, but you're talking about an additional separate-but-complementary feature, right? For conveniently selecting comment blocks?
What I meant was the following: if you have a comment that looks something like this: // A comment that has uneven and
// too-long lines in it. Now I'm just typing text to make it longer, because there's nothing further useful to say
// in this comment. And you select all three lines and run the proposed command from this issue, then you get this: // A comment that has uneven and too-long
// lines in it. Now I'm just typing text
// to make it longer, because there's
// nothing further useful to say in this
// comment. In other words, if you've selected consecutive lines of comments, it smartly re-wraps them as a single comment. That's all. |
That's exactly what I meant :)
In that case having a comment text object will make it even easier to do this. I was investigating treesitter text objects before the sticky key PR; I'll see what I can come up with. |
Kakoune did badly in this. We should take into account with support for multiple types of line comments. Like rust, |
@pickfire Block comments (e.g. |
Another use case: git commit messages. vim seems to do it by default for those. So I can simply type without needing to remember manually wrapping at the column restriction. |
This commit doesn't exactly get us on par with vim, since this requires a command to reflow and Helix won't be doing it as you type. That said, both soft wrap and "live-reflowing" are features I'd like to work on. Editing Markdown is kind of terrible without at least one of the two. |
Often when writing code you want to hard-wrap your text to a maximum line-width. A command to re-wrap selected text would be great for that purpose.
Personally, I find myself mostly wanting to do this in code comments, more than in the code itself (which is often better handled by auto-formatters). So I would suggest supporting re-wrapping of code comments as a first-class aspect of this feature.
The text was updated successfully, but these errors were encountered: