This content originally appeared on DEV Community and was authored by keshav Sandhu
Using keyboard shortcuts in VS Code can greatly improve your productivity by reducing the need for a mouse and speeding up navigation, editing, and other common tasks. Here’s a list of some essential VS Code shortcuts and tricks to help you code more efficiently:
1. Basic Navigation
Open Command Palette:
Ctrl + Shift + P(orCmd + Shift + Pon Mac)
Quickly access commands or search for actions.Open File/Folder:
Ctrl + P(orCmd + Pon Mac)
Quickly open a file by typing its name.Toggle Sidebar (Explorer, Search, etc.):
Ctrl + B(orCmd + Bon Mac)
Hide or show the sidebar to save screen space.-
Navigate Between Open Tabs:
-
Next Tab:
Ctrl + Tab -
Previous Tab:
Ctrl + Shift + Tab
-
Next Tab:
Go to Definition:
F12
Jumps to the definition of a function, variable, or class.Peek Definition:
Alt + F12(orOption + F12on Mac)
Opens a small window with the definition without navigating away.Go to Line:
Ctrl + G(orCmd + Gon Mac)
Jump to a specific line in the current file.Open/Close Integrated Terminal:
Ctrl + ~(orCmd + ~on Mac)
Quickly toggle the integrated terminal.
2. Editing Shortcuts
Copy Line Up/Down:
Alt + Shift + Up/Down(orOption + Shift + Up/Downon Mac)
Copy the current line up or down.Move Line Up/Down:
Alt + Up/Down(orOption + Up/Downon Mac)
Move the current line or block of code up or down.Delete Line:
Ctrl + Shift + K(orCmd + Shift + Kon Mac)
Instantly delete the current line.Duplicate Line:
Shift + Alt + Down(orShift + Option + Downon Mac)
Duplicate the selected line or block of code.Select All Occurrences of Word:
Ctrl + D(orCmd + Don Mac)
Select the next occurrence of the word under the cursor for multi-cursor editing.Select All Occurrences in File:
Ctrl + Shift + L(orCmd + Shift + Lon Mac)
Select all instances of the selected word or variable in the file.Expand/Contract Selection:
Shift + Alt + Right/Left(orCmd + Shift + Right/Lefton Mac)
Expand or shrink the selection based on syntax context (useful for selecting entire functions, blocks, or HTML tags).-
Multi-Cursor Editing:
-
Add Cursor Below:
Ctrl + Alt + Down(orCmd + Option + Downon Mac) -
Add Cursor Above:
Ctrl + Alt + Up(orCmd + Option + Upon Mac) This allows you to add multiple cursors for editing in multiple places at once.
-
Add Cursor Below:
Jump to Matching Bracket:
Ctrl + Shift + </code> (orCmd + Shift + </code> on Mac)
Moves the cursor to the matching bracket (useful for nested code).
3. Refactoring and Code Formatting
Rename Symbol:
F2
Renames the selected symbol throughout the codebase.Format Document:
Shift + Alt + F(orCmd + Option + Fon Mac)
Automatically formats the entire document based on the language’s conventions (can be configured in settings).Auto-Import Suggestions:
Ctrl + .(orCmd + .on Mac)
Show quick fix options like importing a missing module.Toggle Comment Line:
Ctrl + /(orCmd + /on Mac)
Quickly comment/uncomment a line.Comment/Uncomment Block:
Shift + Alt + A(orCmd + Option + Aon Mac)
Comment or uncomment an entire block of code.
4. Search and Replace
Find:
Ctrl + F(orCmd + Fon Mac)
Opens the search box to find text in the current document.Find and Replace:
Ctrl + H(orCmd + Hon Mac)
Opens the search and replace panel.Find All Occurrences in Workspace:
Ctrl + Shift + F(orCmd + Shift + Fon Mac)
Searches for text across the entire workspace.Replace in Files:
Ctrl + Shift + H(orCmd + Shift + Hon Mac)
Replaces occurrences across files in the workspace.
5. File and Workspace Management
Quickly Toggle Between Open Editors:
Ctrl + 1, 2, 3...
Switch between multiple editor groups using the number keys.New File:
Ctrl + N(orCmd + Non Mac)
Creates a new file.Close Current Editor:
Ctrl + W(orCmd + Won Mac)
Closes the current tab/editor.Split Editor:
Ctrl + \(orCmd + \on Mac)
Splits the editor into multiple views.Reopen Closed Tab:
Ctrl + Shift + T(orCmd + Shift + Ton Mac)
Reopens the last closed tab.Cycle Between Editors:
Ctrl + PageUp/PageDown
Switches between open tabs.
6. Git and Source Control
Open Git View:
Ctrl + Shift + G(orCmd + Shift + Gon Mac)
Opens the Git source control view.Stage All Changes:
Ctrl + Shift + A
Stages all the changed files for commit.Commit Staged Changes:
Ctrl + Enter(orCmd + Enteron Mac)
Commits staged changes with a message.View Git Diff:
Ctrl + D
Opens a diff view to compare file changes.
7. Terminal Shortcuts
New Terminal Instance:
Ctrl + Shift +(orCmd + Shift +on Mac)
Opens a new terminal window.Switch Terminal Tabs:
Ctrl + PageUp/PageDown
Move between multiple terminal tabs.Focus on Terminal:
Ctrl +(orCmd +on Mac)
8. Extensions & Debugging
Open Extensions View:
Ctrl + Shift + X(orCmd + Shift + Xon Mac)
Opens the Extensions sidebar where you can install or manage extensions.Start Debugging:
F5
Starts the debugger based on the selected configuration.Step Over:
F10
Steps over to the next line during debugging.Step Into:
F11
Steps into the function during debugging.
Tips & Tricks for Efficiency
Zen Mode:
Ctrl + K Z(orCmd + K Zon Mac)
Enter Zen Mode to remove all distractions (hide all sidebars, status bars, and tabs).Change All Occurrences: Select a word and press
Ctrl + Shift + L(orCmd + Shift + Lon Mac) to select all occurrences in the file, making bulk edits faster.Go to File Symbol: Press
Ctrl + Shift + O(orCmd + Shift + Oon Mac) to jump to functions, classes, or symbols within a file.
By mastering these shortcuts and tricks, you’ll be able to navigate, edit, and refactor code more quickly, reducing the reliance on the mouse and enhancing your overall productivity.
This content originally appeared on DEV Community and was authored by keshav Sandhu