Skip to content
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

feat: add bidirectional motion repeat with selection support #12884

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

willbush
Copy link

@willbush willbush commented Feb 16, 2025

Closes #12877
Fixes #8761

Related discussion: #8495

This continues @Aqaao's initial work here.

Taking into consideration @the-mikedavis's comment here.

  • Add reverse motion repeat A-> (A-S-.) to complement existing repeat (Alt-.)

    I'm completely open to suggestions for an alternative key binding. I personally use a heavily modified keymap to support Colemak-DHm. I'm planning to bind this to ' / " (select register &) in my config.

  • New commands:

    • repeat_last_motion_reverse
    • extend_repeat_last_motion
    • extend_repeat_last_motion_reverse
  • Add extend variants for both forward/reverse motion repeat

    Why add extend variants of repeat_last_motion? This is motivated by @pascalkuthe's comment:

    This is the only consistent behaviour because select mode is not supposed to be special. Instead it should just be a keymap like window mode/space mode/goto mode,... You can already bind extend_next_char in normal mode and it would be strange if that would extend the selection (similarly it would be strange if you biud find_next_char in visual mode and itwould be similarly strange if reperating that would extend the selection.

    The extend variants override the last movement (i.e Move / Extend) to always extend.

  • Update documentation and tutor

  • Note this also fixes some issue I run into when using find / till on <ret> Basically, it works as expected now. I haven't searched through existing issues to see if any can be closed yet. couldn't find any existing issues. Think f / t + <ret> is not something people would expect to do anything.

Short demos

find / till . either starting in normal or select mode and switching:

find_till.mp4

repeat motion and reverse repeat on next paragraph:

paragraph.mp4

repeat motion and reverse on next function:

function.mp4

- Add Alt-Shift-. binding to reverse repeat last motion
- Split repeat_last_motion into normal/reverse variants
- Support extending selections with repeat motions
- Update documentation and tutor to reflect new commands
Add MotionMode handling in goto_diag_{next,prev} commands to support
reverse repeat operations.
goto_next_change and goto_prev_change now support reverse repeat (changes
direction).

extend_repeat_last_motion and extend_repeat_last_motion_reverse will now
override the movement (move / extend) behavior if for some reason someone binds
extend_repeat_last_motion in normal mode it will work as expected.
- Update tree-sitter object navigation to support reverse direction
- Add reverse direction support for goto_ts_object_impl and select_sibling_impl
- Update move_node_bound_impl to handle reverse motions
@nik-rev
Copy link
Contributor

nik-rev commented Feb 16, 2025

I'm also using Colemak DH and Alt + Shift anything is literally impossible for me to press. Nice to see someone else using it!

I think A-S-. is the one that makes the most sense and one that feels consistent with other keybindings in the editor

@willbush
Copy link
Author

I'm also using Colemak DH and Alt + Shift anything is literally impossible for me to press. Nice to see someone else using it!

I think A-S-. is the one that makes the most sense and one that feels consistent with other keybindings in the editor

Think @pascalkuthe uses it too! What keyboard you guys use? Something with qmk firmware I'm guessing. I use this little thing
https://github.com/foostan/crkbd so yea I'm also not a fan of alt-S bindings either. :D

@nik-rev
Copy link
Contributor

nik-rev commented Feb 16, 2025

I'm also using Colemak DH and Alt + Shift anything is literally impossible for me to press. Nice to see someone else using it!
I think A-S-. is the one that makes the most sense and one that feels consistent with other keybindings in the editor

Think @pascalkuthe uses it too! What keyboard you guys use? Something with qmk firmware I'm guessing. I use this little thing https://github.com/foostan/crkbd so yea I'm also not a fan of alt-S bindings either. :D

This is my layout

image
image
image

I'm also using corne keyboard! Really comfortable. The numbers are in weird positions, but I placed them there for a reason. :)

I was trying to find a solution for how I can possibly have a natural combination for Shift + Alt. Tried for a long time, but nothing feels good. Everything adjustments feels like a compromise to make that combination possible. So I've just decided to remap any Shift + Alt I come across.

@willbush
Copy link
Author

I was trying to find a solution for how I can possibly have a natural combination for Shift + Alt. Tried for a long time, but nothing feels good. Everything adjustments feels like a compromise to make that combination possible. So I've just decided to remap any Shift + Alt I come across.

Following is off-topic nerding out about keyboards for anyone reading this PR:

Here's mine

The numbers are in weird positions

Ha love it! looks like the type of insane micro-optimization I would try.

One thing that stands out to me about your layout are the arrow keys on the primary layer. Personally, I put these on the raise layer (right mid thumb cluster button for me) in the same position as vim movement keys. Seems like that would be easier to reach and would also free up a lot of possibilities on your primary layer.

I have one deviation from Colemak-DH. I swap the , and y key. When learning the layout I realize the thing I hate most about the layout is typing the words "you're", "your", and "you". The word "you" et al. is one of the most common words in English and is insanely hard to type in the standard Colemak positions.

I tried the swap on: https://colemakmods.github.io/mod-dh/analyze.html and this is an improvement in score on Colemak-DH due to swapping the same-finger bigrams e, with the ey which occurs about half as often. Typing the word "you" et al. is still not amazing, but it's much easier than before. Another minor downside is words that end with ly don't finger roll as nicely on the top row.

Anyway, moving arrow keys off main layer opens up a lot of things you can do. You can move , back to the right. have a dedicated alt key etc.

Personally, I like having number row across all my main layers so I can hold the layer down with the opposite hand that's pressing the number key. I get away with this by having a dedicated layer for F keys (LOWER + v takes me to FN layer).

Interesting that you press space with your left hand. I've always wondered if that would be a better balance in typing across both hands!

@willbush
Copy link
Author

This is my layout

Also funny to me that you're not the first person I've run into that uses this keyboard: meow-edit/meow#626 (comment)

Thought this would be a lot more rare.

@willbush
Copy link
Author

Reviewing this again, I realized it makes sense to be able to reverse the motion of expand_selection / shrink_selection. So I made a commit for that.

Here a breakdown of motions where reverse repeat last motion applies:

applies:

goto_prev_paragraph
goto_next_paragraph

find_till_char
find_next_char
extend_till_char
extend_next_char
till_prev_char
find_prev_char
extend_till_prev_char
extend_prev_char

goto_next_diag
goto_prev_diag

goto_next_change
goto_prev_change

select_next_sibling
select_prev_sibling

move_parent_node_end
move_parent_node_start
extend_parent_node_end
extend_parent_node_start

goto_next_function
goto_prev_function
goto_next_class
goto_prev_class
goto_next_parameter
goto_prev_parameter
goto_next_comment
goto_prev_comment
goto_next_test
goto_prev_test
goto_next_entry
goto_prev_entry

expand_selection
shrink_selection

does not apply

select_all_siblings
select_all_children

select_textobject_around
select_textobject_inner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Undo repeat_last_motion A-. (repeat_last_motion) does not select as expected
2 participants