Search code examples
sublimetext3

how to set ctrl+[ instead of escape in sublime text 3?


I use vim mode in sublime text 3, I want to use ctrl+[ instead of esc.

This is my keymap config:

[
    // vim_mode
    // exit insert mode, same to 'esc'
    { "keys": ["ctrl+["], 
        "command": 
        [ 
            "single_selection", 
            "clear_fields", 
            "hide_auto_complete", 
            "hide_overlay", 
            "hide_popup", 
            "exit_insert_mode", 
            "enter_visual_mode",
            "hide_overlay", 
            "clear_fields", 
            "hide_popup", 
            "hide_auto_complete", 
            "exit_insert_mode", 
            "enter_visual_mode",
            "hide_panel",
        ],
        "args": { "cancel": true },
        "context":
        [
            { "key": "num_selections", "operator": "not_equal", "operand": 1 }
        ]
    },
    { "keys": ["ctrl+["], 
        "command": 
        [
            "hide_overlay", 
            "clear_fields", 
            "hide_popup", 
            "hide_auto_complete", 
            "exit_insert_mode", 
            "enter_visual_mode",
            "hide_panel",
            "hide_overlay", 
            "clear_fields", 
            "hide_popup", 
            "hide_auto_complete", 
            "exit_insert_mode", 
            "enter_visual_mode",
            "hide_panel",
        ],
        "args": { "cancel": true },
        "context":
        [
            { "key": "has_next_field", "operator": "equal", "operand": true }
        ]
    },
    { "keys": ["ctrl+["], 
        "command": 
        [
            "hide_overlay", 
            "clear_fields", 
            "hide_popup", 
            "hide_auto_complete", 
            "exit_insert_mode", 
            "enter_visual_mode",
            "hide_panel",
            "hide_overlay", 
            "clear_fields", 
            "hide_popup", 
            "hide_auto_complete", 
            "exit_insert_mode", 
            "enter_visual_mode",
            "hide_panel",
        ],
        "args": { "cancel": true },
        "context":
        [
            { "key": "has_prev_field", "operator": "equal", "operand": true }
        ]
    },
    { "keys": ["ctrl+["], 
        "command": 
        [
            "hide_overlay", 
            "clear_fields", 
            "hide_popup", 
            "hide_auto_complete", 
            "exit_insert_mode", 
            "enter_visual_mode",
            "hide_panel",
            "hide_overlay", 
            "clear_fields", 
            "hide_popup", 
            "hide_auto_complete", 
            "exit_insert_mode", 
            "enter_visual_mode",
            "hide_panel",
        ],
        "args": { "cancel": true },
        "context":
        [
            { "key": "panel_visible", "operator": "equal", "operand": true }
        ]
    },
    { "keys": ["ctrl+["], 
        "command": 
        [
            "hide_overlay", 
            "clear_fields", 
            "hide_popup", 
            "hide_auto_complete", 
            "exit_insert_mode", 
            "enter_visual_mode",
            "hide_panel",
            "hide_overlay", 
            "clear_fields", 
            "hide_popup", 
            "hide_auto_complete", 
            "exit_insert_mode", 
            "enter_visual_mode",
            "hide_panel",
        ],
        "args": { "cancel": true },
        "context":
        [
            { "key": "overlay_visible", "operator": "equal", "operand": true }
        ]
    },
    { "keys": ["ctrl+["], 
        "command": 
        [
            "hide_overlay", 
            "clear_fields", 
            "hide_popup", 
            "hide_auto_complete", 
            "hide_panel",
            "exit_insert_mode", 
            "enter_visual_mode",
            "hide_overlay", 
            "clear_fields", 
            "hide_popup", 
            "hide_auto_complete", 
            "exit_insert_mode", 
            "enter_visual_mode",
            "hide_panel",
        ],
        "args": { "cancel": true },
        "context":
        [
            { "key": "popup_visible", "operator": "equal", "operand": true }
        ]
    },
    { "keys": ["ctrl+["], 
        "command": 
        [
            "hide_overlay", 
            "clear_fields", 
            "hide_popup", 
            "hide_auto_complete", 
            "exit_insert_mode", 
            "enter_visual_mode",
            "hide_panel",
            "hide_overlay", 
            "clear_fields", 
            "hide_popup", 
            "hide_auto_complete", 
            "exit_insert_mode", 
            "enter_visual_mode",
            "hide_panel",
        ],
        "args": { "cancel": true },
        "context":
        [
            { "key": "auto_complete_visible", "operator": "equal", "operand": true }
        ]
    },
    {
        // auto_complete
        // use tab to forward to next completion source
        "keys": ["ctrl+n"],
        "command": "move",
        "args": { "by": "lines", "forward": true },
        "context":
        [
            { "key": "auto_complete_visible" },
        ],
    },
    {
        // auto_complete
        // use tab to backward to prev completion source
        "keys": ["ctrl+p"],
        "command": "move",
        "args": { "by": "lines", "forward": false },
        "context":
        [
            { "key": "auto_complete_visible" },
        ],
    },
]

after I map all escape commands and vim exit insert mode to ctrl+[, when I type this: enter image description here

the ctrl+[ doesn't work, the selection will not disappear until I press the esc.

why ctrl+[ cannot make it disappear ?


Solution

  • You can create a single command to exit to a clean command mode by installing ChainOfCommand (or creating a macro) and just call all "exit" commands at once. Just install it and paste this into your keymap:

    {
        "keys": ["ctrl+["],
        "command": "chain",
        "args": {
            "commands": [
                ["hide_overlay"],
                ["hide_popup"],
                ["hide_auto_complete"],
                ["hide_panel", {"cancel": true}],
                ["clear_fields"],
                ["single_selection"],
                ["exit_insert_mode"],
                ["exit_visual_mode"],
            ]
        },
    },