Sublime Forum

Key-binding bug and workaround

#1

key-binding (mapping | shortcut) does not work as described in the
docs I found around !
Instead of replacing the binding of the default file, the user file
binding just** add another key** to the command !!!

It does replace it in the menu but the original “default” key is still
active as well…… and thus not available for another command. I
will not bother explaining why this is noooot gooooood.

My workaround is to Cut (not copy) the relevant line(s) from the default keys
file, paste it into the users’ file and bind it to another command
or none. (yes it’s possible but not fun)

Ok this is for the ST3 latest windows version as of 22.01.2017; still using
vim under Linux but will let you know the behavior there as soon as I
will fully commit to ST3 :wink:

0 Likes

#2

Whatever documentation you found on this is incorrect; this is exactly how it works. Sublime key bindings map a command to a key sequence, they do not map a key sequence to a command.

For example, the key Ctrl+S is mapped to the save command by default:

{ "keys": ["ctrl+s"], "command": "save" },

If I decide that I want this to be Ctrl+Shift+Alt+S instead, I could add the following mapping to my custom key bindings:

{ "keys": ["ctrl+alt+shift+s"], "command": "save" },

Now there are two key sequences that map to the save command; I didn’t tell Sublime “I want the save command to be bound to Ctrl+Alt+Shift+S”, I told it “I want the save command to be bound to Ctrl+Alt+Shift+S as well”.

This is not true; do you have an example of this happening? In the situation above, Ctrl+S is still mapped to save, but you can remap that key if you wanted to.

In the example above, if you don’t want the original key binding to still be active, map it to a command that does not exist; then when the key is pressed, nothing happens:

{ "keys": ["ctrl+s"], "command": "noop" },

As you probably know, this is not a good idea. Updating a shipped file will either get undone on the next update or will mask changes, neither of which is a good thing.

4 Likes