amp icon indicating copy to clipboard operation
amp copied to clipboard

[Feature Request] Reflow selected text like Vim’s gq and gw

Open multinormal opened this issue 3 years ago • 3 comments

When writing long comments, or prose in LaTeX or Markdown etc., it is often necessary to reflow/rewrap text to ensure no lines are longer than the line width, while also ensuring commented code remains correctly commented (eg if # characters begin a comment, then all lines in the reflowed comment block should start with that character, and such characters that began lines should not end up midway through the reflowed text). Doing this manually is tedious and potentially error-prone. Reflowing text can be done with Vim’s gq and gw commands, for example. It would be great to have this feature in Amp.

Example:

# This is a comment that is too long and should be reflowed.

Could be reflowed as:

# This is a comment that is
# too long and should be
# reflowed.

multinormal avatar Apr 16 '21 21:04 multinormal

I forked this very recently to add 'reflowing' (I called it justification). I've begun to implement just the simple greedy algorithm in a new selection::justify command. I still at the very least need to add tests and make sure it actually works (it probably doesn't), but it's there.

oldaccountdeadname avatar Apr 16 '21 22:04 oldaccountdeadname

@multinormal I wasn't aware Vim had a solution to this; I've been doing this manually (albeit only with multi-line git commit comments) for years. :sweat_smile:

@LincolnAuster happy to review your PR once it's in a good place. Building that as a command feels like the right first step!

jmacdonald avatar Apr 17 '21 17:04 jmacdonald

It would be nice to reformat with ">" quotes like gq} in vim for usenet/mail posts. Then I can replace vim for mails usenet posts, with amp ;)

bmaxa avatar May 16 '21 10:05 bmaxa