Keyboard shortcut to turn autocomplete on and off

@mbylst I’ve been looking for the same thing - a single-key shortcut to quickly disable the mighty cursor tab when it’s doing too much and starts editing the code around the cursor when I’m just trying to fix some indentations.

Since I couldn’t find anything online, I tried to come up with my own solution. Maybe it’s not the most elegant way to do it, but I tied so many different things and this was the only thing that actually worked in the end.

Here’s the setup:
First we need extensions, so hit Ctrl+Shift+X and in the marketplace find and install these two:
“Settings Cycler” by hoovercj
“multi-command” by ryuta46

A couple lines of code in the user settings.json and keybindings.json.

settings.json:

{
    // ... other settings ...
    "cursor.cmdk.useThemedDiffBackground": true,
    "settings.cycle": [
        {
            "id": "toggleCursorTabSet_disable",
            "values": [{
                    "cursor.cmdk.useThemedDiffBackground": false,
                    "editor.cursorStyle": "line-thin"
            }]
        },
        {
            "id": "toggleCursorTabSet_enable",
            "values": [{
                    "cursor.cmdk.useThemedDiffBackground": true,
                    "editor.cursorStyle": "line"
            }]
        }
    ],
    "multiCommand.commands": [
        {
            "command": "multiCommand.toggleCursorTabEnable",
            "sequence": [
                "editor.action.enableCppGlobally",
                "settings.cycle.toggleCursorTabSet_enable"
            ]
        },
        {
            "command": "multiCommand.toggleCursorTabDisable",
            "sequence": [
                "editor.cpp.disableenabled",
                "settings.cycle.toggleCursorTabSet_disable"
            ]
        }
    ]
}

keybindings.json:

[
    // ... other keybindings ...
    // this is optional : removes the default keybinding for ctrl+tab
    {
        "key": "ctrl+tab",
        "command": "-workbench.action.quickOpenPreviousRecentlyUsedEditorInGroup",
        "when": "!activeEditorGroupEmpty"
    },
    // cursor tab toggle keybindings
    {
        "key": "ctrl+tab",
        "command": "multiCommand.toggleCursorTabEnable",
        "when": "!config.cursor.cmdk.useThemedDiffBackground"
    },
    {
        "key": "ctrl+tab",
        "command": "multiCommand.toggleCursorTabDisable",
        "when": "config.cursor.cmdk.useThemedDiffBackground"
    }
]

Don’t forget to remove any other keybindings for ‘Ctrl+Tab’ or choose an alternative shortcut that isn’t already in used.

That should do the trick! :slightly_smiling_face:
By the way, I chose the ‘cursor.cmdk.useThemedDiffBackground’ setting to store the toggle state, as it doesn’t seem to have much impact anyway. It’s a bit messy, but hey… it works! You could also replace it with a different boolean key-value in settings.json. It’s necessary for the when-condition in the keybindings.

3 Likes