Time-Saving VS Code Shortcuts
Do you ever watch experienced programmers perform magic tricks in their text editors and wonder how they did it?
Me too. That’s why I compiled this list of VS Code keyboard shortcuts you need to know. You’ll be shaving seconds off of every line you code.
View & Edit Shortcuts
Press ⌘K ⌘S to open up keybindings. You can easily browse or search for the command to view a helpful reference to its shortcut.
You can also add / edit / remove commands and their shortcuts using this guide.
Add Cursors
Using the mouse: option + click
Using the keyboard: command + option + up or down
Duplicate Line / Selection
Have your cursor on the line you want or select the lines and press shift + option + up or down. Both will create a new copy of the targeted line(s) of code underneath the selection.
Multi-Select
Select next instance of the word your cursor is on / phrase you have selected: command + d
Select all instances: command + shift + l
Global Search & Replace
Open up the search panel with command + shift + h
When you do this it automatically populates the search input area with your cursor, so you can immediately start typing your search term.
Press tab and type your replacement term and press option + command + enter
Press enter again to confirm and press command + b to close the panel.
Note: You can exclude files or instances of the search term from being replaced or specify which files to target using the controls in the panel.
Cursor Jumping & Selection
Jump cursor word-by-word: option + left or right
Expand selection word-by-word: option + shift + left or right (NOT up or down — this will cause the selection to be duplicated).
Expand selection line-by-line: function + shift + left, right, up or down
Move Lines
Move line(s) up or down in your file: option + arrow up or down
Easy Formatting
To tab the whole file: option + shift + f
Only selected code: (⌘K ⌘F)
VS Code has default formatters for JavaScript, TypeScript, JSON, and HTML, and you can download extensions to support additional languages.
Keymaps
Press (⌘K ⌘M) to search for and install emulators to bring keyboard shortcuts from other text editors to VS Code.
Toggle Terminal
If your cursor is in the editor, control + backtick will jump the cursor to the terminal and open a terminal if it’s not already open. If the cursor is in the terminal, control + backtick will close the terminal and return the cursor to its last position in the code file.
Conclusion
And that’s only scratching the surface! Feel like a l33t h@cker yet? Share your favorite VS Code tricks in the responses.
Additional Resources
VS Code’s official condensed keyboard shortcut guide for Mac, Windows, and Linux.