← Back to DevBytes

VS Code Keyboard Shortcuts: Complete Guide

VS Code Keyboard Shortcuts: Complete Guide

Visual Studio Code has become the most popular code editor in the world, and one of the biggest reasons for that is its powerful keyboard shortcut system. While most developers know the basics like copy and paste, mastering VS Code's shortcuts can dramatically increase your productivity, reduce strain on your wrists, and help you navigate complex codebases with ease. This guide covers everything from the fundamentals to advanced customization techniques.

What Are VS Code Keyboard Shortcuts?

VS Code keyboard shortcuts are key combinations that trigger specific commands within the editor without requiring you to use the mouse. They range from simple text editing operations to complex multi-cursor editing, navigation, and even integrated terminal commands. VS Code ships with hundreds of built-in shortcuts, and you can customize every single one of them.

The shortcuts are organized into categories like Basic Editing, Navigation, Search, Editor Management, and Display. Each operating system has slightly different default keybindings because of platform-specific conventions, but the underlying commands remain the same.

Why Keyboard Shortcuts Matter

Learning keyboard shortcuts is one of the highest-ROI investments a developer can make. Here is why they matter:

Getting Started: The Command Palette

The single most important shortcut to learn is the Command Palette. It gives you access to every command in VS Code, including ones that do not have default keyboard shortcuts assigned. On Windows and Linux, press Ctrl+Shift+P. On macOS, press Cmd+Shift+P.

When you open the Command Palette, you will see a dropdown with a > prefix. Start typing to filter commands. For example, typing "format" will show all formatting-related commands. This is invaluable when you are learning, because you can search for a command by name and see its shortcut displayed on the right side of the list.

Essential Editing Shortcuts

These are the shortcuts you will use dozens of times per day. The examples below use Windows/Linux notation. On macOS, replace Ctrl with Cmd unless otherwise noted.

// Basic text editing
Ctrl+X          // Cut line (no selection needed)
Ctrl+C          // Copy line (no selection needed)
Ctrl+V          // Paste
Ctrl+Shift+K    // Delete current line
Ctrl+Enter      // Insert line below
Ctrl+Shift+Enter // Insert line above
Alt+Up          // Move line up
Alt+Down        // Move line down
Shift+Alt+Down  // Copy line down
Shift+Alt+Up    // Copy line up
Ctrl+D          // Select next occurrence of current selection
Ctrl+Shift+L    // Select all occurrences of current selection

The Ctrl+D shortcut deserves special attention. It is one of the most powerful editing features in VS Code. When you select a word and press Ctrl+D, VS Code finds and selects the next occurrence of that word. You can press it repeatedly to select multiple occurrences, and then type to edit them all simultaneously. This is a form of multi-cursor editing.

Multi-Cursor Editing

Multi-cursor editing is where VS Code truly shines. You can place multiple cursors in your file and edit all of them at once. Here are the key shortcuts:

// Multi-cursor shortcuts
Alt+Click           // Add a cursor at click position
Ctrl+Alt+Down       // Add cursor below
Ctrl+Alt+Up         // Add cursor above
Ctrl+D              // Add next occurrence to selection
Ctrl+Shift+L        // Add all occurrences to selection
Ctrl+U              // Undo last cursor operation
Shift+Alt+I         // Add cursors to end of each selected line
Alt+Drag            // Column (box) selection

A practical example: imagine you have a list of variables and you want to convert them all to camelCase. You could select the first variable name, press Ctrl+Shift+L to select all occurrences, and then retype them. Or you could use Shift+Alt+I to place a cursor at the end of every selected line and append a semicolon to all of them at once.

Navigation Shortcuts

Navigating a large codebase efficiently is critical. These shortcuts help you move through files, symbols, and definitions quickly:

// File and symbol navigation
Ctrl+P              // Quick Open - search files by name
Ctrl+Shift+O        // Go to Symbol in current file
Ctrl+T              // Go to Symbol in workspace
Ctrl+G              // Go to line number
Ctrl+Shift+\        // Jump to matching bracket
F12                 // Go to Definition
Alt+F12             // Peek Definition (inline preview)
Ctrl+K Ctrl+I       // Show hover (tooltip)
Alt+Left            // Go back
Alt+Right           // Go forward
Ctrl+Tab            // Switch between open editors
Ctrl+Shift+Tab      // Switch editors in reverse

The Ctrl+P Quick Open dialog is particularly powerful. You can type partial file names, and VS Code uses fuzzy matching to find them. You can also type @ within Quick Open to search symbols, or : followed by a number to jump to a specific line.

Search and Replace

VS Code has robust search capabilities, both within a single file and across the entire workspace:

// Search shortcuts
Ctrl+F              // Find in file
Ctrl+H              // Find and Replace in file
Ctrl+Shift+F        // Find in Files (workspace search)
Ctrl+Shift+H        // Replace in Files
Alt+Enter           // Select all matches in Find widget
Alt+C               // Toggle case-sensitive search
Alt+W               // Toggle whole word search
Alt+R               // Toggle regex search
Enter               // Next match (in Find widget)
Shift+Enter         // Previous match (in Find widget)

The workspace search (Ctrl+Shift+F) supports regular expressions, file inclusion and exclusion patterns, and case sensitivity. You can also use the search panel to preview replacements before applying them across your entire project.

Editor and Window Management

When you are working with multiple files, managing your editor layout becomes important:

// Editor management
Ctrl+\              // Split editor
Ctrl+1, Ctrl+2...   // Focus specific editor group
Ctrl+K Ctrl+Right   // Move editor to next group
Ctrl+K Ctrl+Left    // Move editor to previous group
Ctrl+W              // Close editor
Ctrl+K W            // Close all editors
Ctrl+K Ctrl+W       // Close all editors in all groups
Ctrl+B              // Toggle sidebar
Ctrl+J              // Toggle bottom panel
Ctrl+`              // Toggle integrated terminal

Code Formatting and Refactoring

VS Code includes powerful code formatting and refactoring tools that work with language extensions:

// Formatting and refactoring
Shift+Alt+F         // Format document
Ctrl+K Ctrl+F       // Format selection
F2                  // Rename symbol (works across files)
Ctrl+.              // Quick Fix / Refactor menu
Ctrl+Space          // Trigger IntelliSense suggestions
Ctrl+Shift+Space    // Trigger parameter hints
Ctrl+/              // Toggle line comment
Shift+Alt+A         // Toggle block comment
Ctrl+K Ctrl+X       // Trim trailing whitespace

The F2 rename shortcut is especially useful because it performs a semantic rename. Unlike a simple find-and-replace, it understands the language's scoping rules and only renames the actual symbol, not string literals or comments that happen to contain the same text.

Integrated Terminal Shortcuts

The integrated terminal is a core part of many developers' workflows. Here are the key shortcuts for working with it:

// Terminal shortcuts
Ctrl+`              // Toggle terminal visibility
Ctrl+Shift+`        // Create new terminal
Ctrl+Shift+C        // Copy selection (terminal)
Ctrl+Shift+V        // Paste into terminal
Ctrl+Up             // Scroll up
Ctrl+Down           // Scroll down
Alt+Click           // Move cursor to click position in terminal

Customizing Keyboard Shortcuts

One of the best features of VS Code is that every shortcut is customizable. You can change defaults, add new shortcuts for commands that do not have them, and even create complex multi-step keybindings. To open the keyboard shortcuts editor, press Ctrl+K Ctrl+S (or Cmd+K Cmd+S on macOS).

The keyboard shortcuts editor provides a searchable interface where you can view, modify, and reset keybindings. For more advanced control, you can edit the keybindings.json file directly by clicking the icon in the top-right corner of the shortcuts editor.

Here is an example of a custom keybindings.json file:

// Place your key bindings in this file to override the defaults
[
  {
    "key": "ctrl+e",
    "command": "workbench.action.quickOpen"
  },
  {
    "key": "ctrl+p",
    "command": "-workbench.action.quickOpen"
  },
  {
    "key": "ctrl+shift+r",
    "command": "editor.action.rename",
    "when": "editorTextFocus"
  },
  {
    "key": "alt+w",
    "command": "workbench.action.closeOtherEditors",
    "when": "editorTextFocus"
  },
  {
    "key": "ctrl+alt+s",
    "command": "workbench.action.files.saveAll"
  }
]

Notice the minus sign (-) before the command in the second entry. This removes an existing keybinding, which is useful when you want to reassign a shortcut to a different command. The when clause is a context expression that controls when the keybinding is active. For example, "when": "editorTextFocus" means the shortcut only works when a text editor is focused.

Understanding the When Clause Context

The when clause is a powerful feature that lets you create context-sensitive shortcuts. VS Code evaluates these expressions to determine whether a keybinding should fire. Here are some common context keys:

// Common when clause contexts
"when": "editorTextFocus"              // Text editor is focused
"when": "editorLangId == 'javascript'" // Specific language file
"when": "resourceExtname == '.json'"   // Specific file extension
"when": "terminalFocus"                // Terminal is focused
"when": "editorHasSelection"           // Text is selected
"when": "findWidgetVisible"            // Find widget is open
"when": "editorTextFocus && !inDebugMode" // Editor focused and not debugging

You can combine contexts with && (and), || (or), and ! (not). This allows you to create sophisticated keybindings that behave differently depending on what you are doing.

Chord Keybindings

VS Code supports chord keybindings, which are two-key combinations pressed in sequence. The default Ctrl+K prefix is a chord starter. For example, Ctrl+K Ctrl+S opens keyboard shortcuts, and Ctrl+K Ctrl+C comments the current line. You can create your own chord keybindings in keybindings.json:

[
  {
    "key": "ctrl+k ctrl+d",
    "command": "editor.action.formatDocument",
    "when": "editorTextFocus"
  },
  {
    "key": "ctrl+k ctrl+t",
    "command": "workbench.action.selectTheme"
  }
]

Chord keybindings are useful because they effectively multiply the number of available shortcuts without requiring awkward single-key combinations.

Importing and Exporting Shortcuts

If you are switching from another editor, VS Code offers keymap extensions that replicate the shortcuts from popular editors. You can find these in the Extensions marketplace:

These extensions map VS Code commands to the keyboard shortcuts you already know, making the transition much smoother.

Best Practices for Keyboard Shortcuts

To get the most out of VS Code keyboard shortcuts, follow these best practices:

Viewing All Shortcuts for a Specific Extension

When you install extensions, they often introduce new commands. To see all available commands and their shortcuts, open the Command Palette and type the extension name. You can also filter the keyboard shortcuts editor by typing the extension's contribution prefix in the search box.

Some extensions also provide their own shortcut configuration pages. For example, the GitLens extension has an extensive settings panel where you can customize every shortcut it defines.

Debugging Keyboard Shortcut Issues

If a shortcut is not working as expected, there are several things to check. First, open the keyboard shortcuts editor and search for the key combination. If multiple commands are bound to the same key, VS Code shows a conflict warning. Second, check whether another application or your operating system is intercepting the key combination before it reaches VS Code. Third, verify the when clause of your custom keybinding to ensure it applies in the context where you are trying to use it.

You can also use the Developer Tools (accessible via Help > Toggle Developer Tools or Ctrl+Shift+I) to inspect keyboard events and see which command is being triggered.

Conclusion

Mastering VS Code keyboard shortcuts is a journey that pays dividends every single day. By starting with the essentials like the Command Palette, multi-cursor editing, and file navigation, and gradually expanding to custom keybindings and chord shortcuts, you can transform the way you interact with your code. The key is consistent practice and incremental learning. Over time, these shortcuts become muscle memory, and you will find yourself flying through your codebase with a speed and fluidity that mouse-driven workflows simply cannot match. Take the time to invest in your shortcut skills today, and your future self will thank you for the hours saved and the strain avoided.

— Ad —

Google AdSense will appear here after approval

← Back to all articles