If you ever need to show the keybinding for a particular command to the users of your package (e.g. you’re adding some tips functionality), you should avoid resisting the urge to write something like this:
Why is this a bad idea? Because you might change the keybinding of the
command in question (e.g.
projectile-switch-project, but you might
forget to update messages like this. Is there a better way?
substitute-command-keys to the rescue:
This will produce exactly the same message as before and you’re guaranteed the keybinding will always be in sync with the command.
P.S. If you want to check interactively the keybinding of some command use
C-h f (
an example -
C-h f RET projectile-switch-project RET will produce this:
1 2 3 4 5 6 7 8
You can also check which command is bound to some key with