Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Vim like alignment/wrap of selected lines across multiple paragraphs #7176

Closed
ipochi opened this issue May 30, 2023 · 10 comments
Closed

Vim like alignment/wrap of selected lines across multiple paragraphs #7176

ipochi opened this issue May 30, 2023 · 10 comments

Comments

@ipochi
Copy link

ipochi commented May 30, 2023

Below is the screenshot of original document and then it is followed by a screenshot of wrapping of the selected lines
by vim and then helix.

Consider the following text as apart of a larger document and the user has selected the following lines of text.

Original:

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce mollis mi sed malesuada posuere. Donec faucibus eros vitae tortor iaculis, eget sollicitudin ex aliquam abouk
Nullam malesuada ante sed ullamcorper commodo. Vivamus consequat purus ut metus interdum condimentums.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce mollis mi sed malesuada posuere. Donec faucibus eros vitae tortor iaculis, eget sollicitudin ex aliquam abouk
Nullam malesuada ante sed ullamcorper commodo. Vivamus consequat purus ut metus interdum condimentums.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce mollis mi sed malesuada posuere. Donec faucibus eros vitae tortor iaculis, eget sollicitudin ex aliquam abouk
Nullam malesuada ante sed ullamcorper commodo. Vivamus consequat purus ut metus interdum condimentums.
image

Text wrapped with vim (Commands - Select lines and gw, text width set at 100)

image

Text wrapped with Helix (command :reflow , text width set at 100)

image

Not sure if reflow is the correct command here, but I'd like to get a similar behavior of wrapping text across multiple paragraphs like vim, which in my opinion is the correct wrapping.

@CptPotato
Copy link
Contributor

CptPotato commented May 30, 2023

I think the separation of paragraphs should be retained, so I guess this would be a nice enhancement?

For a workaround you can do this:

  • select the text
  • split your selection into paragraphs
    • Alts
    • _ (gets rid of whitespace selections)
    • mip
  • :reflow

@ipochi
Copy link
Author

ipochi commented May 30, 2023

@CptPotato

Thank you for the workaround. Its a handful tbh.

Would love it if somehow this is the default behavior without going through all those keystrokes.

@ipochi
Copy link
Author

ipochi commented May 30, 2023

For others , an explanation about the keystrokes

Alt-s - Split selection on newlines
Alt-x - Shrink selection to line bounds (line-wise selection)
mip - Match mode, Select inside textobject, Match inside paragraph

@CptPotato

Question: How did you have the insight to construct this combination ? asking coz if I have to find out something else that needs more than a few combinations, how should I go about thinking ?

On another note, I would like some help with these please:

Select current line with x and keep pressing x for selecting downward lines, but what needs to be pressed if I have to select lines in the upward direction from the cursor?

Shift - c for multiple cursors, most of the time I accidentally add one more cursor. I then press , to discard all and begin again. How do I revert an additional cursor ?

@CptPotato
Copy link
Contributor

CptPotato commented May 30, 2023

Oops I had a custom keybind (Alt-x) in the workaround I suggested, I updated my last comment with the correct keys.

Question: How did you have the insight to construct this combination ? asking coz if I have to find out something else that needs more than a few combinations, how should I go about thinking ?

Mostly playing around with movements I already knew to see if I can get it to work. Also the command search is very helpful (Space?).

Select current line with x and keep pressing x for selecting downward lines, but what needs to be pressed if I have to select lines in the upward direction from the cursor?

I think by default x keeps the direction of your selection. So if you select one line up manually, pressing x should select upwards.

@ipochi
Copy link
Author

ipochi commented May 30, 2023

Oops I had a custom keybind (Alt-x) in the workaround I suggested, I updated my last comment with the correct keys.

Question: How did you have the insight to construct this combination ? asking coz if I have to find out something else that needs more than a few combinations, how should I go about thinking ?

Mostly playing around with movements I already knew to see if I can get it to work. Also the command search is very helpful (Space?).

Select current line with x and keep pressing x for selecting downward lines, but what needs to be pressed if I have to select lines in the upward direction from the cursor?

I think by default x keeps the direction of your selection. So if you select one line up manually, pressing x should select upwards.

xxxx... keeps selecting the lines downwards.

I mean is there another key combination that would start by selecting the line under the cursor and continue selecting the lines in upwards direction ?

@CptPotato
Copy link
Contributor

xxxx... keeps selecting the lines downwards.

I mean is there another key combination that would start by selecting the line under the cursor and continue selecting the lines in upwards direction ?

You're looking for extend_line_above which isn't mapped to a key by default.

@ipochi
Copy link
Author

ipochi commented May 30, 2023

xxxx... keeps selecting the lines downwards.
I mean is there another key combination that would start by selecting the line under the cursor and continue selecting the lines in upwards direction ?

You're looking for extend_line_above which isn't mapped to a key by default.

Thanks. thats exactly what I am looking for.

Shift - c for multiple cursors, most of the time I accidentally add one more cursor. 
I then press , to discard all and begin again. How do I revert an additional cursor ?

C , adds a new cursor below.
Alt-C , adds a new cursor above.

But I struggle to revert the last added cursor (doesn't matter which direction). Its like I wanted to have 5 additional cursors, but accidentally added 6 , I justnneed to undo the last addition of cursor

@CptPotato
Copy link
Contributor

CptPotato commented May 30, 2023

But I struggle to revert the last added cursor (doesn't matter which direction). Its like I wanted to have 5 additional cursors, but accidentally added 6 , I justnneed to undo the last addition of cursor

I don't think that's possible right now. There's a relevant issue, though: #1596

Edit: let's maybe move this over to a discussion if you have more questions, since this isn't really related to the issue anymore.

@gabydd
Copy link
Member

gabydd commented May 30, 2023

You actually can remove a selection with Alt-, which will remove the last added selection as it will be the primary one unless you rotate your primary selection.

To reflow each paragraph seperately I would split each paragraph with S split selections with regex then use the \n\n then reflow. The current reflow uses https://docs.rs/textwrap/latest/textwrap/fn.refill.html which removes newlines as such it is not aware of paragraphs and at the moment seems to only really be designed for reflowing only one paragraph per selection

@gabydd
Copy link
Member

gabydd commented May 30, 2023

ah this is a duplicate of #2419 see that for some more info

@gabydd gabydd closed this as not planned Won't fix, can't repro, duplicate, stale May 30, 2023
@gabydd gabydd converted this issue into discussion #7179 May 30, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants