Command strategy for `if`


#1

I want to write a command like a-b, except that if the current character is the right part of something in matching_pairs, then I want to behave like m. Similarly, I want a command like a-e that is dual (cares about the left part of matching_pairs.)

I think I could do this by grabbing the current character, sending it to a shell script that then returns the appropriate command sequence. Is that the “Kakoune”-way or is there another strategy for this sort of conditional command?


#2

That’s exactly how I would do it.

You might have some complications getting the “current” character, though. Kakoune provides %val{selection} (spelled $kak_selection in a shell-script) which is the content of the primary selection, not just the character under the cursor. You also get %val{cursor_char_value} ($kak_cursor_char_value) which is the Unicode codepoint of the character under the cursor as a decimal integer, but I don’t think there’s a specific way to get the single character under the cursor as a string.


#3

Yep, that’s how I do it for sublime style multi-cursor mapping. I take length of selection and if it is 1 char, I select word, if it is more then 1 char I jump to the next same word:


#4

Thank you, I am glad to know my intuitions are working out :slight_smile: