Kakoune: How to map "jump forward" and "jump back" in goto mode (e.g. map 'gp' to <c-i>)

625 views Asked by At

I use the dvorak keyboard, and I'd like to reduce strain from reaching for the control key when using <c-i> and <c-o> (to jump backward or forward). I think the ',' and 'p' keys are perfect when combined with the goto menu (e.g. when hitting 'g' first). (For you qwerty folks, that means key positions 'w', 'e', and 'r' on the keyboard, when hit from the goto menu would be jump back, jump to last edit, and jump forward). Thus…

Here is what I want:

1) :map global goto , '<c-o>' -docstring 'jump back'                   // Does not work
2) :map global goto p '<c-i>' -docstring 'jump forward'                // Does not work

However, for inexplicable reasons, neither of these commands work. I tried a bunch of experiments and found a few more strange things:

Tried using user mode instead of goto mode (as stated here: https://github.com/mawww/kakoune/wiki/Implementing-user-mode).

3) :map global user , '<c-o>' -docstring 'jump back'                  // Works
4) :map global user p '<c-i>' -docstring 'jump forward'               // Does not work

Tried various changes to the command string in the map command (back to goto mode)

5) :map global goto p 'd' -docstring 'delete the selection'        // Does not work
6) :map global goto p '/d' -docstring 'delete the selection'       // Works! (Why??)
7) :map global goto p '\d' -docstring 'delete the selection'       // Works! (Why?!?)
8) :map global goto p '\<c-o>' -docstring 'jump back'              // Works! (Why?!!?!!?)
9) :map global goto p '\<c-i>' -docstring 'jump forward'           // Does not work (Why!???)

Thus in summary:

a) Why does #3 work, but #4 doesn't?

b) Why does adding a slash (of either type) in front of a command string (e.g. in #6, #7, #8) make various commands mapped to the goto mode work?

c) How can I get my intentions with #1 and #2 to work? (Technically #8 solves my intention for #1, but I still have no answer for how to do #2)

1

There are 1 answers

0
Dan On

Answer to question A:

As mentioned here,

Beware of keys homonyms like <tab> vs <c-i> and <ret> vs <c-j> and <c-m>

I got <c-i> to work by replacing it with <tab>, like this:

:map global user p '<tab>' -docstring 'jump forward'

Question B:

I was unable to figure out why goto mode is different from user mode, but adding a slash before the command does seem to fix all issues. Another method I found was to add <esc> as the first part of the action keys, which brings it back to normal mode before performing the rest of the keys.

Answer to Question C:

By combining the discoveries from questions A and B, we get the following working map commands:

:map global goto , '\<c-o>' -docstring 'jump back'                   // Works!
:map global goto p '\<tab>' -docstring 'jump forward'                // Works!

...or...

:map global goto , '<esc><c-o>' -docstring 'jump back'                   // Works!
:map global goto p '<esc><tab>' -docstring 'jump forward'                // Works!