-
-
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
Add commands for movement by subwords #8147
Conversation
7c0c195
to
dc301bc
Compare
dc301bc
to
630b383
Compare
I notice many PRs have been marked with |
630b383
to
be4b94d
Compare
2443e60
to
a3e5c21
Compare
Can confirm this works as advertised. Thanks, I was literally making the same change and decided to look for a PR first. |
My only concern is the widespread use of "char_is_word". I wonder in what other ways the definition of "word" is not matching "subword". Many of the places there is little context, just a solitary character. Initially I thought Grapheme::is_word_boundary might be a good avenue but that is only used in doc formatting for some reason.... |
It's been a while since I implemented this, so I can't remember whether I looked at That being said, I've been using this branch in my daily driver since I created it, and so far everything works as expected, so I don't think |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry it took a while to get to this. I think this is a pretty good implementation and I think this feature does carry its weight. I don't think we need to use subword in other places, char_is_word
is to differentiate whitespace and special chars and usually have nothing to do with word segmentation.
Friendly ping to @the-mikedavis to request a review, since this PR already got one approval and is relatively small (ignoring the tests) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, this looks good! I've been thinking about how we should address this use-case for a while and I think this is the best option: adding commands lets you opt into the "subword" behavior and you can use the regular word behavior even at the same time as you show with the example keybindings. (As opposed to adding a config option that affects what we consider to be a word - that would be 'all or nothing')
* Allow moving by subword * Add tests for subword movement
* Allow moving by subword * Add tests for subword movement
What keybinds are people using with this feature? I really like it but I don't want to replace w, b, e, W, B, E with them |
probably prefix it with a key i don't use like |
Is there any intention to add default keybinds for this? |
No I don't see a reason to add default keybindings. The keymap is already pretty crowded |
@the-mikedavis the benefits for me would be:
I suppose it depends if you expect this to be something everybody uses or not |
* Allow moving by subword * Add tests for subword movement
@ntzm - I've been prefixing with [keys.normal.minus]
"minus" = {label = "Select sub word", command = ["move_prev_sub_word_start", "move_next_sub_word_end"]}
"w" = "move_next_sub_word_start"
"b" = "move_prev_sub_word_start"
"e" = "move_next_sub_word_end"
[keys.select.minus]
"minus" = {label = "Select sub word", command = ["extend_prev_sub_word_start", "extend_next_sub_word_end"]}
"w" = "extend_next_sub_word_start"
"b" = "extend_prev_sub_word_start"
"e" = "extend_next_sub_word_end" |
* Allow moving by subword * Add tests for subword movement
This PR adds commands that enable movement within subwords that are snake_cased or camelCased, as previously proposed in discussion #5463. Subwords are delimited by underscores and by transitions from lowercase to uppercase.
The commands are named
{move,extend}_{next,prev}_sub_word_{start,end}
. This PR doesn't add any keybinds.Example usage (
|
characters indicate cursor):|f|oo bar baz
-> move next sub word ->|foo |bar baz
|f|oo_bar_baz
-> move next sub word ->|foo_|bar_baz
|f|ooBarBaz
-> move next sub word ->|foo|BarBaz
Example keybinds: