21 VSCode Keyboard Shortcuts You Should Know
Boost your coding efficiency when working with your favourite code editor
Microsoft’s Visual Studio Code is the favourite code editor of quite a healthy number of developers. All around the globe, developers seem to love working with it due to the plethora of helpful code editing features and extensions it has available that makes our lives just a little bit easier every single day.
However, as familiar the developers are with its extensions marketplace and how to use them effectively, similar is the under-appreciated appeal of the numerous keyboard shortcuts that the editor has built-in for our use.
In this article, I plan to go over the list of my 21 favourite keyboard shortcuts that I use frequently in my own VSCode setup.
Let’s dive right in!
1. Toggle the editor sidebar
Opening and closing the editor sidebar is handy in a number of use cases such as having more space for an extra file you’re trying to read.
Do it quickly with this shortcut:
MacOS: Command + B
Windows/Linux: Ctrl + B
2. Navigate to another file
Quickly swtich to editing another file in the editor without interacting with the sidebar with this shortcut:
Windows/Linux: Ctrl + P
MacOS: Command + P
3. Move easily between tabs
When you have a lot of tabs open and you need to move quickly between them, the most easy way to do it is with this keyboard shortcut:
MacOS: Control + Shift + Tab
Windows/Linux: Ctrl + Shift + Tab
4. Open the command palette
With this shortcut, you can easily open the command palette. The command palette allows you to search through the commands you can use and execute them.
MacOS: Command + Shift + P
Windows/Linux: Ctrl + Shift + P
5. Open the terminal
If you’re like me, you’ll most likely be using the in-built terminal a lot more than the native desktop terminal or command prompt.
This shortcut saves you from moving between the editor and the terminal and allows you to use it side by side with your code.
MacOS: Command + J
Windows/Linux: Ctrl + J
6. Refractoring some text
The best way to find like appearances of your selected text in the code you’re working is by selecting the piece of text and then using:
MacOS: Command + Shift + L
Windows/Linux: Ctrl + Shift + L
It will help you replace all of the occurrences of the selected text in one go.
7. Selecting code blocks
You can easily select a whole code block all without a mouse! Just use:
MacOS: Command + Shift + Option + any arrow key
Windows/Linux: Ctrl + Shift + Alt + any arrow key
8. Copy a line of code below
Copying a single line of code is possible without selecting the line and copying. With your cursor on the line of code that you want to copy, just use:
MacOS: Shift + Option + down arrow key
Windows/Linux: Shift + Alt + down arrow key
and it will copy that line just below it!
9. Cut/move a line of code below
Moving a single line of code is possible without selecting the line and copying. With your cursor on the line of code that you want to copy, just use:
MacOS: Option + down arrow key
Windows/Linux: Alt + down arrow key
and it will move that line just below it!
10. Toggle comments
Toggling a line or a block of code as a comment or not is as easy as using:
MacOS: Command + /
Windows/Linux: Ctrl + /
11. Multi-line comments formatting
Instead of a single line comment, if you want to have a block comment toggle, you can use:
MacOS: Shift +Option + A
Windows/Linux: Shift + Alt + A
12. Format on Save
If you have “auto format on save” setting on inside your VSCode, you don’t need to use this shortcut. However, it is useful to know anyways:
MacOS: Option + Shift + F
Windows/Linux: Ctrl + Shift + F
13. Rename your code file
Simply press the F2
key on any Operating system to rename your code file.
14. Find text
Finding a piece of elusive text in a large code file is a blessing if you remember this shortcut:
MacOS: Control + G
Windows/Linux: Ctrl + G
15. Using a suggested quick fix
You might have noticed some VSCode Quick fix magic appearing on some of your code. It recommends you a few fixes to improve your code quality, remove a small bug like an indentation or semicolon, etc. You can use it by:
MacOS: Command + . (full stop)
Windows/Linux: Ctrl + . (full stop)
16. Go to definition
If you want to look up and navigate instantly to a definition of a variable or a function, use this combination of keys after placing the cursor on the variable/function:
Windows/MacOs:
F12
17. Suggestion Toggle
While working, VSCode and some of its extensions can have some suggestions for your code. This shortcut allows you to toggle the suggestions to see or hide them as you might need:
MacOS: Command + I
Windows/Linux: Ctrl + I
18. See Function Signature
The number of functions we deal with every single day makes it hard to remember the arguments needed for each of them. Luckily, this shortcut helps a ton while passing parameters to a function:
MacOS: Command + Shift + Spacebar
Windows/Linux: Ctrl + Shift + Spacebar
19. Indenting code
Indents, especially if you’re writing Python code, matters a lot and if you want to quickly reformat the indents of a block of code, use this shortcut:
MacOS: Command + [
Windows/Linux: Ctrl + [
20. Insert simultaneously into multiple lines
One of most useful ones if you want to write, for example, a single variable name into 5 different lines but don’t want to do it five times. With this shortcut, you just need to put your cursor at the point where the variable name should go, and then press:
MacOS: Command + Option + up or down arrow
Windows/Linux: Ctrl + Alt + up or down arrow
When you start typing, it will insert the variable into all the lines you selected at once. Just press “Escape
” key to exit out of multi-line cursor state.
…and finally, one of my favourites:
21. Zen Mode Toggle
If you want to work undisturbed, without any distractions in a single code file, you can toggle Zen mode in VSCode with:
MacOS: Command + K, then Z
Windows/Linux: Ctrl + K, then Z
Now that we’ve seen how much value there is in knowing these shortcuts, I would still recommend that you don’t try to learn them all at once.
My advice would be — to start implementing a handful of these every time you’re working in a project in VSCode and slowly, you’ll get better at using them. Over time, it might even end up becoming a muscle memory for you.
Thank you for reading. I hope this has been an informative read.
Liked this article? Tell some friends about it :)
I try my best to make Programming and Data Science as fun and engaging as possible even on my Twitter. Follow me to never miss them!