Sublime Forum

Overriding Anaconda hotkeys under sublime

#1

Hi Community,

I am one of the luckiest guy on earth typing python codes on a hungarian keyboard. On this keyboard the ‘[’ and the ‘]’ can be found by pressing AltGr+f and AltGr+g. Unfortunately these two are overwritten by Anaconda as it is mentioned HERE.

Writing python codes without easy access to square brackets is painful, so I am wondering how can I overwrite (or simply delete) these definitions.

Under Sublime Preferences / Package Settings / Anaconda text / Key Bindings - Default I have seen ctrl+alt+f and ctrl+alt+g defined (ctrl+alt = AltGr), but no matter if I have deleted them I still can’t type brackets with my default keyboard shortcut.

No other plugins use that shortcut. Please let me know if you have any idea how to resolve this issue.

Thanks.

(btw if lets say I want to edit the sublime shortcuts then in that window I can use brackets as I need to)

0 Likes

#2

Did you try to remap those commands?

Deleting something in a Default package file will most likely bring it back after update.

You’d rather try to create a User/Default.sublime-keymap to add an overwriting rule for Anaconda’s default binding. Something like the following snippets should work. The selector ensures it is applied to python code only, which is handled by Anaconda.

{
    "command": "insert", 
    "args": {"characters": "]"}, 
    "keys": ["ctrl+alt+g"],
    "context": [
        {"key": "selector", "operator": "equal", "operand": "source.python"}
    ]
},
{
    "command": "insert", 
    "args": {"characters": "["}, 
    "keys": ["ctrl+alt+f"], 
    "context": [
        {"key": "selector", "operator": "equal", "operand": "source.python"}
    ]
},
1 Like

#3

Thanks man. The snippet makes sense (in terms that I can read it and got the point), but it drops me an error when I insert it to my sublime.keymap file.

See the error message HERE.

0 Likes

#4

You just need to add a comma to the end of line 9. (ctrl+shift+7)

0 Likes

#5

The error message is now gone, but still no brackets :frowning:

0 Likes

#6

Using Sublime Text 3.2., Build 3200, Windows 10, Slovenian keyboard layout:

I managed to solve same problem via: Preferences --> Key Bindings and then replaced all contents with this code similar to previously mentioned:

[
    {
        "command": "insert",
        "args": {"characters": "]"},
        "keys": ["ctrl+alt+g"],
        "context": [
            {"key": "selector", "operator": "equal", "operand": "source.python"}
        ]
    },
    {
        "command": "insert",
        "args": {"characters": "[]"},
        "keys": ["ctrl+alt+f"],
        "context": [
            {"key": "selector", "operator": "equal", "operand": "source.python"}
        ]
    },
]

Difference here from above code is that this code is starting with “[” and ending with “]” (maybe this was assumed in previous post, I don’t know). Second change is in line 12 from this code:

   "args": {"characters": "["},

to this code:

    "args": {"characters": "[]"},

This tweak allows you that when typing lists in Python when you press “[” result output is “[]”. This is same behavior like when you type in “(” and result is “()” or when you type “{” and result is “{}” in your Python code. Just makes it easier to code when parenthesis are opened and closed immediately.

EDIT: Only thing I didn’t know how to do is to put cursor in the middle of “[]”. After some Googling here is the solution:

  1. Install ChainOfCommand (see details on: https://github.com/jisaacks/ChainOfCommand) via Package Control: Install Package (Shortcut: Ctrl+Shift+P)
  2. Put this code via Preferences --> Key Bindings instead of the above:

[
    {
    "command": "insert",
    "args": {"characters": "]"},
    "keys": ["ctrl+alt+g"],
    "context": [
    {"key": "selector", "operator": "equal", "operand": "source.python"}]},
{
    "keys": ["ctrl+alt+f"],
    "command": "chain",
    "args": {
    "commands": [
      ["insert", {"characters": "[]"}],
      ["move", {"by": "characters", "forward": false}]     ,
    ]
    }
}
]

Hope it helps - it bugged me for few hours till I solved it - so I know this can be annoying! :wink:

1 Like