Damo
Damo

Reputation: 6443

Sublime text 3, reasign the + and - away from increase decrease font_size to fold unfold

I want to assign the following key bindings (which you set in the user keymap)

{ "keys": ["ctrl+-"], "command": "fold" },
{ "keys": ["ctrl++"], "command": "unfold" }

But the defaults seem to persist which are

{ "keys": ["ctrl++"], "command": "increase_font_size" },
{ "keys": ["ctrl+="], "command": "increase_font_size" },
{ "keys": ["ctrl+keypad_plus"], "command": "increase_font_size" },
{ "keys": ["ctrl+-"], "command": "decrease_font_size" },
{ "keys": ["ctrl+keypad_minus"], "command": "decrease_font_size" },

I would like to remove all zoom effects so i tried this

{ "keys": ["ctrl++"], "command": "null" },
{ "keys": ["ctrl+="], "command": "null" },
{ "keys": ["ctrl+keypad_plus"], "command": "null" },
{ "keys": ["ctrl+-"], "command": "null" },
{ "keys": ["ctrl+keypad_minus"], "command": "null" }

But the keys still zoom the text, what am i doing wrong here? Maybe if i could just rip them out of the default keymap but that is not editable.

Upvotes: 0

Views: 44

Answers (1)

OdatNurd
OdatNurd

Reputation: 22791

The TL;DR answer to your question is that the reason you're having problems here is that there are more default bindings for the commands that you're trying to run than you've mentioned above (due to some weirdness in Sublime that I don't think I've run across before), and so you're overriding some but not all of the default bindings.

For a longer explanation, we can note that if you use View Package File from the command palette, you can open Default (Linux).sublime-keymap, Default (Windows).sublime-keymap and Default (OSX).sublime-keymap; one of these (based on your question it would appear you're on Windows) is the file that appears in the left hand pane of the key bindings when you use Preferences > Key Bindings, and the other two are for the other platforms supported by Sublime text.

If we search through the default bindings not for the keys that you're trying to redefine, but for the commands that are bound to those keys, we come up with the following:

Windows

    { "keys": ["ctrl++"], "command": "increase_font_size" },
    { "keys": ["ctrl+="], "command": "increase_font_size" },
    { "keys": ["ctrl+keypad_plus"], "command": "increase_font_size" },
    { "keys": ["ctrl+-"], "command": "decrease_font_size" },
    { "keys": ["ctrl+keypad_minus"], "command": "decrease_font_size" },

    { "keys": ["ctrl+equals"], "command": "increase_font_size" },
    { "keys": ["ctrl+shift+equals"], "command": "decrease_font_size" },
    { "keys": ["ctrl+shift+keypad_plus"], "command": "decrease_font_size" },

Linux

    { "keys": ["ctrl++"], "command": "increase_font_size" },
    { "keys": ["ctrl+="], "command": "increase_font_size" },
    { "keys": ["ctrl+-"], "command": "decrease_font_size" },

OSX

    { "keys": ["super+equals"], "command": "increase_font_size" },
    { "keys": ["super+plus"], "command": "increase_font_size" },
    { "keys": ["super+minus"], "command": "decrease_font_size" },

One difference in the bindings seen here is that Windows and Linux use Ctrl for these bindings while MacOS uses Super.

However it's also worth noting a couple of other things as well:

  • Linux binds the commands to +, - and =
  • MacOS binds to plus, minus and equals
  • Windows binds to +, -, =, and equals (plus the keypad equivalents as well)

What's kicking you in the butt here is that Windows also binds the commands using the equals key as seen above, which according to your question you haven't overridden.

There is an internal equivalence between = and equals (as well as the other pairs) that causes Sublime to choose equals over =; you haven't overridden the version of the command that uses equals and thus it still applies.

To truly override the defaults you need to reassign all of the possible bindings for the keys, which would look something like this:

{ "keys": ["ctrl+-"], "command": "fold" },
{ "keys": ["ctrl+="], "command": "unfold" },
{ "keys": ["ctrl++"], "command": "unfold" },
{ "keys": ["ctrl+equals"], "command": "unfold" },

{ "keys": ["ctrl+keypad_plus"], "command": "null" },
{ "keys": ["ctrl+keypad_minus"], "command": "null" },

{ "keys": ["ctrl+shift+equals"], "command": "null" },
{ "keys": ["ctrl+shift+keypad_plus"], "command": "null" },

For completeness this binds ctrl+= and ctrl+equals to the same command, even though only ctrl+equals will always trigger anyway; it's a good reminder that there are multiple keys that do this.

We also bind ctrl++ to that command as well. However this would generally only trigger for keyboards that have a dedicated + key that's not on the numeric keypad (if any).

This is because on the US key layout (which Sublime always uses internally), the + key is the shifted state of the = key; thus you have to press Shift in order to type it, but Sublime seems this as the key ctrl+shift+=; that is, it sees the key and all of it's modifiers, not the shifted state of the key with the ctrl modifier.

Upvotes: 1

Related Questions