# Command strategy for \`if\`

**URL:** <https://discuss.kakoune.com/t/command-strategy-for-if/202>\
**Category:** Recipes & Guides\
**Created:** [November 28, 2018, 9:56pm UTC](https://discuss.kakoune.com/t/command-strategy-for-if/202 "2018-11-28T21:56:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeapostrophe](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/jeapostrophe/32/60_2.png) [@jeapostrophe](https://discuss.kakoune.com/u/jeapostrophe)\
**Post date:** [November 28, 2018, 9:56pm UTC](https://discuss.kakoune.com/t/command-strategy-for-if/202/1 "2018-11-28T21:56:21Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Screwtapello](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/screwtapello/32/12_2.png) [@Screwtapello](https://discuss.kakoune.com/u/Screwtapello)\
**Post date:** [November 29, 2018, 2:22am UTC](https://discuss.kakoune.com/t/command-strategy-for-if/202/2 "2018-11-29T02:22:15Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![andreyorst](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/andreyorst/32/29_2.png) [@andreyorst](https://discuss.kakoune.com/u/andreyorst)\
**Post date:** [November 29, 2018, 12:10pm UTC](https://discuss.kakoune.com/t/command-strategy-for-if/202/3 "2018-11-29T12:10:13Z")

</div>

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:

> [@Sublime Text style multiple cursor select/add mapping](https://discuss.kakoune.com/t/sublime-text-style-multiple-cursor-select-add-mapping/150):
>
> sometimes it feels more natural to select word and jump to next occurence(s), so instead of doing \<a-i\>w\*\<s-n\>\<s-n\>\<s-n\>... multiple times I use this command: define-command -override -docstring "select a word under cursor, or add cursor on next occurrence of current selection" \ select-or-add-cursor %{ execute-keys -save-regs '' %sh{ if [$(expr $(echo $kak\_selection | wc -m) - 1) -eq 1]; then echo "\<a-i\>w\*" else echo "\*\<s-n\>" fi }} map global normal '\<c-d\>' ': se…

---

<div class="post-metadata">

**Author:** ![jeapostrophe](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/jeapostrophe/32/60_2.png) [@jeapostrophe](https://discuss.kakoune.com/u/jeapostrophe)\
**Post date:** [November 30, 2018, 12:39am UTC](https://discuss.kakoune.com/t/command-strategy-for-if/202/4 "2018-11-30T00:39:03Z")

</div>

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