Custom behavior with Setting-Cycler (VSCode)

Sometimes VS Code ships a new feature without a toggle command (editor.minimap.enabled, explorer.autoReveal). Sometimes you want to easily toggle between a light and dark themes. Maybe you want to do something even more complex and toggle multiple settings at once. - Settings Cycler

Customization

Switch focus between editor and integrated terminal

Open the keybindings.json from the editor: CMD-SHIFT-P -> Preferences: Open Keyboard Shortcuts File. Also a nice resource: code.visualstudio.com/docs

// Toggle between terminal and editor focus
{ "key": "ctrl+[Backquote]", "command": "workbench.action.terminal.focus"},
{ "key": "ctrl+[Backquote]", "command": "workbench.action.focusActiveEditorGroup", "when": "terminalFocus"}

Settings Cycler

Add a configuration for the setting, see below. This is can be at the workspace or user level. It’s will be located in the Extension setting: ~/.config/Code/User/settings.json

{
    "settings.cycle": [

Cycling theme

        {
            "id": "colorTheme", // must be unique
            "overrideWorkspaceSettings": false,
            "values": [
                { "workbench.colorTheme": "Monokai" },
                { "workbench.colorTheme": "Monokai Classic" },
                // { "workbench.colorTheme": "Sublime Material Theme - Dark" },
                { "workbench.colorTheme": "Red" },
                { "workbench.colorTheme": "Default Light+" }
            ]
        }

Cycling sort order in Explorer

        {
            "id": "fileSortOrder",
            "overrideWorkspaceSettings": false,
            "values": [
                { "explorer.sortOrder": "default" },
                { "explorer.sortOrder": "mixed" },
                { "explorer.sortOrder": "fileFirst" },
                { "explorer.sortOrder": "type" },
                { "explorer.sortOrder": "modified" }
            ]
        }

End Cycling configuration

    ]
}

Configure a keyboard shortcut

File > Preferences > Keyboard Shortcuts

This will be located in ~/.config/Code/User/keybindings.json

{
    "key": "ctrl+shift+t",
    "command": "settings.cycle.colorTheme"
},

    {
        "key": "ctrl+alt+o",
        "command": "settings.cycle.fileSortOrder",
    }
Written on September 26, 2020, Last update on October 27, 2023
vscode