How to make a shortcut for a plugin command?

Hi all,

I want to make a shortcut to a plugin command. The plugin is Delapouite’s kakoune-buffers, which I find tremendously useful. Just a keyboard shortcut is missing for my workflow.

I want to set either a mapping or an alias to buffer-by-index command. I tried using both, but failed. My idea is to use gn 2 to go to buffer 02, gn 8 to go to buffer 08, and so on…

Here are my attempts:

map global goto n 'buffer-by-index'

map global user n 'buffer-by-index'

alias global n 'buffer-by-index'    #(since the plugin is "locked", I assume it can see the buffer numbers)

The line (obviously, I just use one of those at one time) is the very last after the plugin has been loaded in my kakrc file.

Please, any advise is very welcome ;D

You’re pretty close! The correct syntax is

map global goto n ':buffer-by-index<ret>'

The map command transforms keystrokes, it does not execute commands. So you have to pretend that you’re executing the command manually, and write it that way.

1 Like

Lesson learned! Thanks!

This triggers a question. If I write <ret> after the buffer-by-index command, I never have the chance to indicate which buffer I want to go to.

How could I make it happen?

(I forgot to enclose <ret> in the second line above and was invisible, @raiguard ).

just add a spacing character after buffer-by-index in your mapping and remove <ret>.
This will result in prompting state waiting for your parameter when you use this shortcut.

No, it’s not working.

I can see the n in the goto pipe menu, but I cannot make it work as an alias (bash alias type) for the buffer-by-index command.

If you make a mapping in normal mode, the keys on the right-hand side will be “typed” in normal mode. Thus, the first key needs to be a : to switch to prompt mode, then you can “type” the rest of the command.

If you make a mapping in goto mode, the keys on the right-hand side will be “typed” in goto mode. Thus, the first key probably needs to be <esc> to switch to normal mode, followed by : to switch to prompt mode, then you can “type” the rest of the command.

1 Like

Finally I understand it.

Thanks a lot! Just a miserable extra <esc> and to understand how shortcuts work.