Say No to Mouse: Vs code shortcuts for easing coding
keshav Sandhu
Posted on October 12, 2024
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 + P
on Mac)
Quickly access commands or search for actions.Open File/Folder:
Ctrl + P
(orCmd + P
on Mac)
Quickly open a file by typing its name.Toggle Sidebar (Explorer, Search, etc.):
Ctrl + B
(orCmd + B
on 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 + F12
on Mac)
Opens a small window with the definition without navigating away.Go to Line:
Ctrl + G
(orCmd + G
on 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/Down
on Mac)
Copy the current line up or down.Move Line Up/Down:
Alt + Up/Down
(orOption + Up/Down
on Mac)
Move the current line or block of code up or down.Delete Line:
Ctrl + Shift + K
(orCmd + Shift + K
on Mac)
Instantly delete the current line.Duplicate Line:
Shift + Alt + Down
(orShift + Option + Down
on Mac)
Duplicate the selected line or block of code.Select All Occurrences of Word:
Ctrl + D
(orCmd + D
on 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 + L
on Mac)
Select all instances of the selected word or variable in the file.Expand/Contract Selection:
Shift + Alt + Right/Left
(orCmd + Shift + Right/Left
on 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 + Down
on Mac) -
Add Cursor Above:
Ctrl + Alt + Up
(orCmd + Option + Up
on 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> (or
Cmd + 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 + F
on 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 + A
on Mac)
Comment or uncomment an entire block of code.
4. Search and Replace
Find:
Ctrl + F
(orCmd + F
on Mac)
Opens the search box to find text in the current document.Find and Replace:
Ctrl + H
(orCmd + H
on Mac)
Opens the search and replace panel.Find All Occurrences in Workspace:
Ctrl + Shift + F
(orCmd + Shift + F
on Mac)
Searches for text across the entire workspace.Replace in Files:
Ctrl + Shift + H
(orCmd + Shift + H
on 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 + N
on Mac)
Creates a new file.Close Current Editor:
Ctrl + W
(orCmd + W
on 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 + T
on 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 + G
on 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 + Enter
on 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 + X
on 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 Z
on 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 + L
on Mac) to select all occurrences in the file, making bulk edits faster.Go to File Symbol: Press
Ctrl + Shift + O
(orCmd + Shift + O
on 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.
Posted on October 12, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.