VS Code SetupIntermediate

How to Create Custom Snippets and Keybindings for AI Workflows

Speed up AI-assisted coding with reusable code snippets and custom keyboard shortcuts for chat and edit actions.

8 minIntermediate

The fastest AI workflow is one where the actions you repeat are a single keystroke away. VS Code lets you define custom code snippets and rebind any command to a shortcut. This guide creates a snippet for a common scaffold and binds the AI chat and edit commands to keys that suit you.

What you need

  • VS Code installed
  • At least one AI assistant set up, such as Copilot or Continue
  • About 6 minutes

Step 1: Open the snippets file

Open the Command Palette with Ctrl+Shift+P or Cmd+Shift+P and run Snippets: Configure Snippets. Pick a language, such as javascript, to open that language's snippet file. Each snippet has a prefix that triggers it, a body, and a description.

VS Code - Command Palette
> Configure Snippets
----------------------------------------
Snippets: Configure Snippets
Snippets: Insert Snippet
Searching for the snippets command.

Step 2: Write a snippet

Add an entry to the JSON file. The dollar-sign placeholders are tab stops your cursor jumps between. The example creates a quick test scaffold you can flesh out with help from your AI assistant.

javascript.json (User Snippets)
{
  "Test block": {
    "prefix": "tst",
    "body": [
      "describe(\"$1\", () => {",
      "  it(\"$2\", () => {",
      "    $0",
      "  });",
      "});"
    ],
    "description": "Jest describe + it scaffold"
  }
}
Let AI fill the body
Type your prefix to drop in the scaffold, then use inline chat or completions to fill the assertions. The snippet gives the structure and the AI writes the content, which is faster than either alone.

Step 3: Open the keybindings editor

Run Preferences: Open Keyboard Shortcuts from the Command Palette to browse bindings, or Preferences: Open Keyboard Shortcuts (JSON) to edit the raw file. Search for a command like Copilot chat or Continue to find its command id.

Step 4: Bind AI commands to keys

Add bindings to keybindings.json. The example below opens Continue's chat and the Copilot inline chat on shortcuts that are easy to reach. Choose key combinations that are not already taken, or VS Code will warn you of a conflict.

keybindings.json
[
  {
    "key": "ctrl+alt+c",
    "command": "continue.focusContinueInput"
  },
  {
    "key": "ctrl+alt+i",
    "command": "inlineChat.start"
  }
]
VS Code - Keyboard Shortcuts
Keyboard Shortcuts [ continue ]
----------------------------------------
Focus Continue Input Ctrl+Alt+C User
Start Inline Chat Ctrl+Alt+I User
A custom binding shown in the shortcuts editor.

Result

You can drop in a scaffold with a three letter prefix and open your AI chat or inline edit with one shortcut. The repeated parts of your workflow are now muscle memory, which is where most of the real time savings come from.

Watch related tutorials

Tags
#snippets#keybindings#productivity#shortcuts