Sometimes VS Code ships a new feature without a toggle command (
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.
This extension allows configuring commands to cycle through settings. At its simplest, this allows toggling things such as the minimap and statusbar visibility. At it's most complex, it allows cycling through lists of complex object values.
(See below) for how to use it.
Note: The configuration schema has changed in v1.0.0. I'm sorry for the breaking change, but if the extension detects old settings it will prompt to migrate them.
How to Use:
There are two ways to configure commands. Directly in the keybindings file using the
settings.cycle command with args, or by adding
settings.cycle to user or workspace settings.
By default, the extension will only modify user settings unless the
overrideWorkspaceSettings option is set to true for a group. When true, it will still default to user settings unless there is already a workspace setting in place that it can override, in which case ALL of the specified settings will be set in workspace settings.
"settings.cycle.warnOnWorkspaceSettingsCollisions": true will give a visual warning when a command fails.
Option 1: Keybindings.json only
If you like to keep your settings files small, you can use keybindings.json to pass the settings directly to the
settings.cycle command as args as shown below:
"id": "zen", // must be unique
"values": [ // Note: use the same settings in each values object
Option 2: User settings + Keybindings.json
Step 1: Add a configuration for the setting
"id": "colorTheme", // must be unique
"workbench.colorTheme": "Default Dark+"
"workbench.colorTheme": "Default Light+"
Step 2: Configure a keyboard shortcut
id will generate a command that looks like
settings.cycle.<id>. So to configure a keybinding to toggle between the values set for
colorTheme, add something like this to
If there are issues, set
"settings.cycle.logLevel": "log", copy the output, and submit an issue.
A gitter user asked if it was possible to toggle
explorer.autoReveal via a keyboard shortcut. It isn't, but I realized how general this problem was. Then @rebornix from the VS Code team chimed in and showed how this idea could be further expanded to work for multiple settings at once and be declared directly in the keybindings. Read his blog post about it here.
This is a part of the my API Playground repository. Each subdirectory is a self-contained extension that demonstrates a particular API, repros a bug, answers a stackoverflow question, etc.
- Commands - The commands API provides a way to add commands which can be triggered from the command palette or via key bindings. As demonstrated in this extension, they can be generated dynamically at runtime to create rich, semantic commands, or a single command can be used by passing different args to it.
- Configuration - The configuration API handles user and workspace settings for vscode. It allows extensions to react to configuration changes, to read configuration settings, and to write to them.
- v1.0.0 schema changes and idea for using command args come from @rebornix and his toggle extension.
settings.cycle configuration schema
settings.cycle command which takes the new schema as args
- Can now cycle multiple settings at once
- Can now add arguments directly to the keybindings
settings.cycle.<setting name> commands