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

Movement by subwords #8147

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

Conversation

JeftavanderHorst
Copy link

@JeftavanderHorst JeftavanderHorst commented Sep 2, 2023

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:

[keys.normal]
W = 'move_next_sub_word_start'
B = 'move_prev_sub_word_start'
E = 'move_next_sub_word_end'

[keys.select]
W = 'extend_next_sub_word_start'
B = 'extend_prev_sub_word_start'
E = 'extend_next_sub_word_end'

@JeftavanderHorst
Copy link
Author

I notice many PRs have been marked with S-waiting-on-review but this one hasn't, is there anything I need to do to request a review?

@the-mikedavis the-mikedavis added S-waiting-on-review Status: Awaiting review from a maintainer. A-command Area: Commands labels Feb 10, 2024
@shaleh
Copy link
Contributor

shaleh commented Apr 2, 2024

Can confirm this works as advertised. Thanks, I was literally making the same change and decided to look for a PR first.

@shaleh
Copy link
Contributor

shaleh commented Apr 2, 2024

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....

@JeftavanderHorst
Copy link
Author

It's been a while since I implemented this, so I can't remember whether I looked at char_is_word. There is at least one other definition of "word" that I didn't update, which is in text objects. Meaning miW is still Match inner WORD, instead of Match inner sub word. Sub word text objects are implemented in #8658 though, if you need them.

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 char_is_word is too important. If the core devs are interested I can work on this as well, but for now, I tried to keep the diff as small as possible (except for the tests) so that I can easily keep up with master.

Copy link
Member

@pascalkuthe pascalkuthe left a 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.

@JeftavanderHorst
Copy link
Author

Friendly ping to @the-mikedavis to request a review, since this PR already got one approval and is relatively small (ignoring the tests)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-command Area: Commands S-waiting-on-review Status: Awaiting review from a maintainer.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants