Kakoune: Reverse search <a-/> orthoganality

Created on 2 Dec 2020  路  5Comments  路  Source: mawww/kakoune

While regular searching with / directions of n and <a-n> are natural and orthogonal i.e. former jumps down and latter jumps up. However while reverse searching with <a-/> directions of n and <a-n> are the same as in regular search. I expected that in reverse search n and <a-n> would reverse their directions respectively, but this is not the case. The reverse part of <a-/> is only in its initial jump and afterwards I still have to hold alt key to keep reverse direction, which in my opinion is not so orthogonal.

Most helpful comment

I think this behaviour could make for a good plugin, or at least a good snippet for the users' configuration. Here's my quick implementation of it:

define-command -hidden -params 1 search_direction %{ evaluate-commands %sh{
    case "$1" in
        up) echo "
            map global normal n <a-n>
            map global normal <a-n> n
            exec <a-/>
        ";;

        down) echo "
            map global normal n n
            map global normal <a-n> <a-n>
            exec /
        ";;
    esac
} }

map global normal <a-/> ': search_direction up<ret>'
map global normal / ': search_direction down<ret>'

If you do decide to adapt the above code and use it in your user configuration, could you please document it in the wiki?

All 5 comments

Setting a side effect on primitives predicated on which one was used previously doesn't sound great, it's not predictable.

One problem I can see would occur upon a user using a-/, then *. I think the user would expect that subsequently hitting n would select the next (downward) match, but since * modifies the search register / directly (and shouldn't assume that the user's intent is to search downward), hitting n would select the previous (upward) match.

I think this behaviour could make for a good plugin, or at least a good snippet for the users' configuration. Here's my quick implementation of it:

define-command -hidden -params 1 search_direction %{ evaluate-commands %sh{
    case "$1" in
        up) echo "
            map global normal n <a-n>
            map global normal <a-n> n
            exec <a-/>
        ";;

        down) echo "
            map global normal n n
            map global normal <a-n> <a-n>
            exec /
        ";;
    esac
} }

map global normal <a-/> ': search_direction up<ret>'
map global normal / ': search_direction down<ret>'

If you do decide to adapt the above code and use it in your user configuration, could you please document it in the wiki?

Nice solution!

could you please document it in the wiki?

Yes of course, I think placing it under Editing paragraph. Is it ok?

Sounds good, I rarely care about what's on the wiki, so feel free to create pages as you see fit.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

abitofalchemy picture abitofalchemy  路  3Comments

dpc picture dpc  路  4Comments

Delapouite picture Delapouite  路  4Comments

lenormf picture lenormf  路  3Comments

a12l picture a12l  路  3Comments