helix icon indicating copy to clipboard operation
helix copied to clipboard

feat: new `subword` text object

Open nik-rev opened this issue 1 year ago • 4 comments

this is a new text object which operates on parts of snake_case, kebab-case, camelCase, PascalCase and /path/case

It's a subword, so it's mapped to s

Below is a table showcasing various use-cases of this new text object. * is just an indicator for where the cursor is and is not part of the text

mis selects an inner subword, mas selects an outer subword which includes the delimiter. d deletes the selection.

before inner (misd) outer (masd
snake_case_lon*g snake_case_ snake_case
snake_ca*se_long snake__long snake_long
snake__ca*se__longier snake____long snake__long
snake__case__long*ier snake__case__ snake__case
c*amelCaseLong camelCase CaseLong
camelCa*seLong camelLong camelLong
camelCAseNotRE*Ally camelCAseNot camelCAseNot
camelCA*seNotREAlly camelNotREAlly camelNotREAlly
snake_Ri*ding_a_Camel_Case snake__a_Camel_Case snake_a_CamelCase
sn*ake_Riding_a_Camel_Case _Riding_a_Camel_Case Riding_a_Camel_Case
P*ascalCaseLong CaseLong CaseLong
tast*y-kebab-case -kebab-case kebab-case
tasty-kebi*ab-case tasty--case tasty-case
path/som*ewhere/../case path//../case path/../case
../.*./path/case/ ..//path/case ../path/case
../path/case/som*ewhere ../path/case/ ../path/case

nik-rev avatar Nov 07 '24 21:11 nik-rev

I'm certainly not opposed to this being merged, but when I implemented https://github.com/helix-editor/helix/pull/8147, I didn't feel the text object was necessary, since you can emulate match_inner_sub_word by chaining move_prev_sub_word_start and move_next_sub_word_end, which is the same amount of keypresses (depending on your config).

JeftavanderHorst avatar Nov 08 '24 23:11 JeftavanderHorst

I'm certainly not opposed to this being merged, but when I implemented #8147, I didn't feel the text object was necessary, since you can emulate match_inner_sub_word by chaining move_prev_sub_word_start and move_next_sub_word_end, which is the same amount of keypresses (depending on your config).

I mean, similar can be said about word, for example. You can use be to select the inner word, but it's really handy to have a word text object at your disposal.

Another benefit is that you don't need to think about which keys specifically to use, or assign them yourself.

nik-rev avatar Nov 08 '24 23:11 nik-rev

Nice feature! I noticed it doesn't look the subword object was added to the match context menu, though.

rockboynton avatar Jan 02 '25 23:01 rockboynton

Nice feature! I noticed it doesn't look the subword object was added to the match context menu, though.

Okay, I just added it

nik-rev avatar Jan 03 '25 13:01 nik-rev