Kakoune: Cannot use `:` in builtin mode bindings

Created on 1 Jan 2021  路  8Comments  路  Source: mawww/kakoune

Steps

  1. map global goto a ':fail lol<ret>'
  2. gh
  3. ga

Outcome

l lol
map global goto a ':fail lol<ret>'

Due to how mappings work, this means goto_commands() in src/normal.cc is seeing : as the key it needs to executed, which is obviously unbound in that mode. The same is true for view mode.

Expected

The : prompt should execute fail lol.

bug

All 8 comments

Mappings in insert mode are executed in insert mode, mappings in normal mode are executed in normal mode, mappings in prompt mode are executed in prompt mode. The outlier here is user modes - mappings in user modes are also executed in normal mode.

Mappings let you redefine which keys invoke which Kakoune operations, but the operations are just the built-in mappings. So if you map global normal j k the j is what gets redefined, and the k is the built-in mapping for "go up a line".

Insert mode has built-in mappings you can map onto; normal mode has built-in mappings you can map onto; prompt mode has built-in mappings you can map onto, but user modes by definition do not have any built-in mappings, so the right-hand-side has to be interpreted in some other mode, and Normal mode is the obvious choice.

Because modes like goto and view look like user-modes, it's reasonable to expect them to behave the same way, but they do have built-in mappings that you might want to map onto. In fact the similar <a-a> and <a-i> modes have built-in mappings (specifically, c and <a-semicolon>) whose only purpose is to have custom mappings mapped onto them!

So, the behaviour you describe is consistent, but the rule is "does this mode have built-in mappings", not "does this mode present an info box of available mappings".

Thanks for your explanation, that makes sense.

Do you think it would make sense to have a binding to : / ; similar to that of object mode's <a-semicolon> in both goto and view modes? Or would their behaviors be too inconsistent for those contexts?


For now, though, I'll just have to settle for my own user mode, copying all the built-in commands except for the one I want to modify.

You can prefix the command with <esc> or <a-semicolon> for a single command to an object menu to acceed %val{count}, %val{select_mode} and %val{object_flags}.

Try:

2<a-i><a-semicolon>echo %val{count} %val{select_mode} %val{object_flags}<ret>

See the [Expansions] page for more info.


The support for <a-semicolon> in goto could make sense to know the select mode.

Ah, of course: I could just add <esc> to the front of the mapping to get back to normal mode. Thanks for reminding me of the obvious.

Whoops, forgot to close this.

Thanks again for reminding me of the obvious, @alexherbo2.

@cole-h Can you open an issue to support <a-semicolon> in submodes? Currently, it is not possible to forward a count or distinguish the select mode (replace and extend with g and G from the goto mode for example).

I think it should actually be whatever the modifier is for accessing the submode. That's why I thought <a-i> used <a-;>: so one doesn't have to take their hands off the Alt key. It might become a bit of a pain if we need to use e.g. g<a-;> rather than g;.

But if my intuition re: <a-i><a-;> is incorrect, we can definitely do <a-;> for all of them.

<a-i> is one of the various flavors of the object mode and for example ] is not Alt-based.

<a-;> might not be ergonomic in all case but is compatible with insert and prompt modes.

It also reminds a Shift less (on qwerty) to the : command.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MasterOfTheTiger picture MasterOfTheTiger  路  4Comments

1g0rb0hm picture 1g0rb0hm  路  3Comments

hwmack picture hwmack  路  4Comments

Delapouite picture Delapouite  路  4Comments

notramo picture notramo  路  3Comments