Refer to begin-of/end-of selection, like BOL/EOL (^/$)

Hi all,

aim: to delete leading and trailing whitespace chars in an arbitrary selection - not to be confused with unselecting leading/trailing whitespace which is what the _ cmd does.

I can’t figure out how to do this, but the most natural solution that my mind wants to reach for is to enter selection mode and use an equivalent of ^ and $ regex ops but instead of operating on line terminals it would operate on selection terminals (which kak already knows about via the a-; a-: a-S keys). I guess some might frown upon having a kak-specific regex extension but I find myself wishing it existed fairly regularly as it’s a natural concept we use all the time to navigate and extend selections via those keys.

Please let me know if I’ve missed some obvious feature that makes the above a trivial task and/or if there’s an equally powerful primitive available for other use cases… happy to learn!

You might be interested in the \A and \z regex assertions, which match at the beginning and end respectively of the selected string.

As per Screwtapello’s reply, \A and \z are relevant. This seems to work:

  • select the starting spaces with s\A\s+<ret>
  • delete them
  • type <a-u> to restore your previous selection (it will be restored without the starting spaces you just deleted)
  • type s\s+\z<ret> to select the ending spaces
  • delete them
1 Like

Ahhhh… I got stuck thinking in kak terms and didn’t even think of checking the regex spec - never seen those before.

Thanks guys!

Aside from \A and \z, other goodies to remember are \Q and \E (see the Quoting section); they can spare you a lot of escaping pain :slight_smile:.

1 Like

oh that’s a good one! thanks for sharing :slight_smile: