keyboard shortcut to turn autocomplete on and off

Is there a way to turn autocomplete on and off with a keyboard shortcut?

Since for those of us who are practicing python for example, many times we do not want it to show us how to do something, but rather do it ourselves. On the other hand, autocomplete is still very useful to create documentation, comments and things like lists quickly and be more productive when practicing, so I think a quick way to activate and deactivate autocomplete would be great

Hi @Enzopin ,

Does this assist?

I’m doing this in keybindings.json:

  {
    "key": "ctrl+shift+x",
    "command": "editor.cpp.disableenabled"
  },
  {
    "key": "ctrl+shift+c",
    "command": "editor.action.enableCppGlobally"
  }

Seems to be working. I wish cmd shift x would toggle but I’m not sure the when statement value that would check the cpp enabled state

1 Like

I would personally love it if I could disable autocomplete suggestions for editing regular text, but get suggestions for code. It’s hard to think while writing when the editor keeps suggesting text.

To set a keybinding for this:

  1. Type Command/Ctrl + Shift + P.
  2. Go to “preferences: open keyboard shortcuts”
  3. Search ‘cursor tab’
  4. Set an enable hotkey and a disable hotkey.

No option to have a single hotkey that toggles ASAIK.

You might be able to accomplish this using the setting described here:

It’d be great if you could set a single key for toggle, rather than having to have a different key for enable and disable.

Please teach a man how to fish - where did you find these command names?

When you assign a key combination, it shows up in the JSON file.

@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