Skip to main content
CodingMarble

Interview questions and cheat sheets

VS Code Keyboard Shortcuts Cheat Sheet for Windows and Mac

The VS Code shortcuts worth learning first are Quick Open, the Command Palette, multi-cursor selection, move line, rename symbol and the debugger step keys. Each is listed below as Windows/Linux key followed by the macOS key, and you can see or change any of them in the Keyboard Shortcuts editor.

By CodingMarble · Published · 5 min read

An empty notebook beside a keyboard and a pen
Photo: Marissa Grootes on Unsplash

How to read this sheet and find any shortcut

Every shortcut below is a default in current VS Code, written as the Windows and Linux key first and the macOS key in brackets. Where a key is the same on both, it is only written once. Defaults can differ by keyboard layout, by operating system version, and by extensions, so if a key does nothing on your machine, check the Keyboard Shortcuts editor described next rather than assuming you made a mistake.

Learn a handful at a time. Pick the two or three actions you repeat most, such as opening files and moving lines, and force yourself to use the keys for a week before adding more. Chords, written as Ctrl+K then Ctrl+S, mean press the first combination, release, then press the second.

Multi-cursor and editing

Multi-cursor editing is the biggest time saver in the editor, because one typed change applies to every cursor at once. Start with select-next-occurrence and add the rest when you need them.

  • Ctrl+D (Cmd+D) selects the word under the cursor, and pressing it again adds the next matching occurrence.
  • Ctrl+Shift+L (Cmd+Shift+L) selects every occurrence of the current selection at once.
  • Alt+Click (Option+Click) adds a cursor wherever you click.
  • Ctrl+Alt+Up or Down (Cmd+Option+Up or Down) adds a cursor on the line above or below.
  • Shift+Alt+I (Shift+Option+I) puts a cursor at the end of every selected line.
  • Ctrl+U (Cmd+U) undoes the last cursor action without undoing text.
  • Alt+Up or Down (Option+Up or Down) moves the current line or selection; Shift+Alt+Up or Down (Shift+Option+Up or Down) copies it.
  • Ctrl+Shift+K (Cmd+Shift+K) deletes the current line.
  • Ctrl+Enter (Cmd+Enter) inserts a new line below, and Ctrl+Shift+Enter (Cmd+Shift+Enter) inserts one above.
  • Ctrl+L (Cmd+L) selects the whole line, and repeating it extends the selection downward.
  • Ctrl+/ (Cmd+/) toggles a line comment, and Shift+Alt+A (Shift+Option+A) toggles a block comment.
  • Ctrl+] and Ctrl+[ (Cmd+] and Cmd+[) indent and outdent lines.
  • Shift+Alt+F (Shift+Option+F) formats the whole document, and Ctrl+K Ctrl+F (Cmd+K Cmd+F) formats only the selection.

Search, replace and refactoring

  • Ctrl+F (Cmd+F) finds text in the current file, and Enter or F3 (Cmd+G) jumps to the next match.
  • Ctrl+H (Option+Cmd+F) opens find and replace in the current file.
  • Ctrl+Shift+F (Cmd+Shift+F) searches across every file in the workspace.
  • Ctrl+Shift+H (Cmd+Shift+H) opens replace across files; review the preview before you apply it.
  • F2 renames a symbol everywhere the language service can see it, which is safer than a text replace.
  • Ctrl+. (Cmd+.) opens Quick Fix suggestions such as adding an import or fixing a lint warning.
  • Ctrl+Shift+R (Ctrl+Shift+R) opens the refactor menu when the language supports it, for example extracting a function.
  • Shift+Alt+O (Shift+Option+O) organizes imports in languages that support it, such as TypeScript.
  • Ctrl+Space (Ctrl+Space) triggers code suggestions manually.

Rename with F2 for code, and use search and replace for plain text. A text replace on a short name like id will change unrelated words, whereas F2 follows the real symbol. Turn on the regular expression toggle in the search box only when you mean it, and always glance at the preview list before replacing in many files.

Terminal and debugging

  • Ctrl+` (Ctrl+`) shows or hides the integrated terminal, and Ctrl+Shift+` (Ctrl+Shift+`) creates a new terminal.
  • F5 starts debugging, or continues when paused; Shift+F5 stops, and Ctrl+Shift+F5 (Cmd+Shift+F5) restarts.
  • F9 toggles a breakpoint on the current line.
  • F10 steps over a call, F11 steps into it and Shift+F11 steps out of it.

On many laptops, and on a Mac by default, the function keys control volume or brightness unless you hold Fn, so the debug keys can look broken. Hold Fn or change the keyboard setting rather than rebinding everything. In the debugger, set a breakpoint with F9, start with F5, then step with F10 and F11 while watching the Variables pane.

Practical tip: open the Keyboard Shortcuts editor, search for a command you use daily and look at its Source column. If an extension has claimed a key, you can see which one and remove or rebind it.

How to see and rebind shortcuts

Press Ctrl+K Ctrl+S (Cmd+K Cmd+S) to open the Keyboard Shortcuts editor. You can search by command name or by key, and typing a key combination in the search box shows what it is bound to. Double-click a row to record a new key, and right-click for options such as removing a binding or changing its when-condition. The Command Palette entry called Preferences: Open Keyboard Shortcuts (JSON) opens the keybindings file as text, which is easier to copy between machines.

JSON· keybindings.json: one custom binding and one removed default
[
  {
    "key": "ctrl+alt+d",
    "command": "editor.action.duplicateSelection",
    "when": "editorTextFocus"
  },
  {
    "key": "ctrl+shift+k",
    "command": "-editor.action.deleteLines"
  }
]

A command name beginning with a minus sign removes a default binding. If you want shortcuts from another editor, extension packs exist for that purpose; check the current Marketplace listing and its reviews before installing, as with any extension.

Settings that save time

Open Settings with Ctrl+, (Cmd+,), or edit settings.json through the Command Palette. Two options change the daily rhythm most. Format on save runs your formatter each time you save, so style arguments disappear from reviews. Auto save removes the habit of pressing Ctrl+S altogether, though it can trigger file watchers and live reload more often, so some people prefer saving on focus change.

JSON· settings.json: format on save and auto save when focus leaves the editor
{
  "editor.formatOnSave": true,
  "files.autoSave": "onFocusChange",
  "editor.tabSize": 2,
  "files.trimTrailingWhitespace": true
}

Format on save needs a formatter for the language, either built in or installed, and the project may set its own through a configuration file such as Prettier's. If saving does nothing, open the Command Palette, run Format Document With, and choose a default formatter. Settings can be per user or per workspace; keep project rules in the workspace so teammates share them.

Need this built properly for your business?

CodingMarble is a remote studio in India that builds websites, apps and games on fixed packages with the scope written down before payment. Try the free tools we run, or start a project when you are ready.