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.
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.
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.
{
"Test block": {
"prefix": "tst",
"body": [
"describe(\"$1\", () => {",
" it(\"$2\", () => {",
" $0",
" });",
"});"
],
"description": "Jest describe + it scaffold"
}
}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.
[
{
"key": "ctrl+alt+c",
"command": "continue.focusContinueInput"
},
{
"key": "ctrl+alt+i",
"command": "inlineChat.start"
}
]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
19:27
1:42:18
28:14
41:09
9:47
8:23