`EBEB` cumulative? `C<a-C>C<a-C>` non-cumulative?

In an attempt to Taking back control of hjkl with modifiers keys :

  • How can I implement a behavior where EBEB would result in 4 words selected instead of one (cummulative vs corrective selection — is that a good tokenization of the cause?)
  • Contrarily, how can I implement a behavior where C<a-C>C<a-C> would result in a corrective single line select (instead of cumulatively 4)?

E always leaves the anchor where it is, and moves the cursor forward. If you want E to always extend the selection, you need to make sure the cursor comes after the anchor before E is executed. In other words:

map global normal E <a-:>E

Likewise, B always moves the cursor backward. There’s no specific command to ensure the cursor comes before the anchor, but there is a command to flip the two:

map global normal B <a-:><a-semicolon>B

I don’t think there’s an easy way to make C and <a-C> corrective, since they create selections as well as modifying them. If I had to do it, I’d probably write a Python script that takes %val{selections_desc}, interprets it, and does the required modification.

Now that I think about it, I’m not sure there would be a sensible definition of non-cumulative C and <a-C>. Let’s say you have selected line 5 and line 10, then you hit C — now lines 5, 6, 10, and 11 are selected. If you invoke non-cumulative-a-C, should that drop lines 6 and 11, or just line 11? What if we started with 8 and 10, and C selected 8, 9, 10, and 11 - what should non-cumulative-a-C do then? What about starting with just 8, and pressing C four times to select 8, 9, 10, and 11?

1 Like

Wow, thank you - first part works perfect:

map global normal       '<a-:><a-semicolon>B'    # <c-H>
map global normal                         'B'    # <c-a-H>
map global normal         '<a-:>E'  # <c-L>
map global normal              'E'  # <c-a-L>

That was already the most useful one! Trying to approach the other issue…

You might be right on that → I might just drop this attempt for the time being. It’s a little annoying for if I overshoot and have not easy way to correct the last additional selection, but the reconquest of hjkl needs also still a little room for improvement :wink:

Remember you can always use ( or ) to switch which is the main selection, and <a-space> to drop that selection specifically. It’s a bit more fiddling around than non-cumulative <a-C> would be, but it can be less fiddling around than hitting <space> and starting from scratch.

1 Like