Moving from keyboard to mouse to perform some action can sometimes be annoying. VS Code has some really nice keyboard shortcuts to help keep me in flow when working with code. In this article, we'll explore 10 must-know VS Code shortcuts that I use on a day to day basis. These shortcuts are not only time-saving but also make you feel like a coding wizard 🧙♀️. Let's dive in!
Disclaimer: Please note that the keyboard shortcuts mentioned are for a MacBook keyboard. Keep this in mind and adapt them to your specific setup as needed.
1. Quick File Navigation with Command ⌘ + P
Even if you are not working in a project with many files this shortcut will come in handy.
Command ⌘ + P
will open the search bar at the top, where you can start typing the name of the file you want to open.
This shortcut allows you to quickly locate and open files without the need to manually navigate through folders, saving you valuable time and ensuring you stay focused on your code.
2. Easily Copy/Cut and Paste Entire Line/Block
I didn't know that I could copy an entire line in VS Code without having to select the whole line. You can simply do Command ⌘ + C or Command ⌘ + X
on the line your cursor is on and it will copy/cut the whole line. Cool, right?
3. Move Code Up and Down / Move Lines Up/Down
Sometimes you just need to take a code block and move it somewhere else either up or down from where it is to do this you have to:
Select the code you want to move and press Option ⌥ + arrow up/down
to move the selected code
If you want to move just one line you can do this without selecting the whole line.
4. Toggle Side Panel and Integrated Terminal
Sometimes all I want, especially when I am working on my 14" laptop screen, is to be able to focus on the file with the code without seeing the sidebar or in-build terminal.
Command ⌘ + B
will show or hide side bar
Command ⌘ + J
will show or hide the in-build terminal
I should mention that I keep my side panel on the right side as all code is left to right and I prefer having more space on the left rather than on the right which is the end of the file.
5. Multi-Cursor Editing
There are times you might want to edit code on multiple lines and to do this you have two options:
-
Option ⌥ + Click
to get multiple cursors where you click and what you type or delete will happen on all the lines where you see the cursors -
select a word
and then pressCommand ⌘ + D
as many times as you need. This adds a cursor on the the same word (if it exists) selected which every press ofCmd + D
and will allow you to change that specific word in all places at the same time. Pretty neat!
6. Navigate a Line of Code Word by Word or from Start to End
Holding Option ⌥ + arrow left/right
will make the cursor go through a line word by word, this works also in the terminal.
If you press Command ⌘ + arrow left/right
you will navigate to the start or end of the line.
Command ⌘ + arrow up/down
takes you to the beginning/end of the file.
7. Search in All Files with Command ⌘ + Shift ⇧ + F
This is one of my favorites. Sometimes you want to quickly search for a function across the whole project. With Command ⌘ + F
you can search the file you are in but if you press Command ⌘ + Shift ⇧ + F
you can search in all files of the project.
8. Go to a Specific Line of Code in the File
To go to a specific line in your file press Control + G
and then enter the line number. That's it! Comes in handy especially when pair programming and your partner asks you to change something on a specific line.
9. Close Current File When You No Longer Need It
Command ⌘ + W
10. Navigate Through Your Open Tabs
Control + Tab
Bonus: Copy the line you are on just below
Put the cursor on the line you would like to copy below and press Option ⌥ + SHIFT + arrow down
. I haven't used this one too much so far.
It's not easy to remember all these shortcuts at once. I recommend having a cheat sheet and starting to incorporate these slowly, building muscle memory over time.
Happy coding 🚀
Top comments (12)
Windows shortcuts would be nice too...
You are right :) Have a look at the windows shortcuts here: code.visualstudio.com/shortcuts/ke...
for windows just replace the command key for ctrl and ⌥ for alt.
One I just learned recently is Ctrl+/ to comment/uncomment the current line.
Great list, Stefi! Appreciate ya sharing. 😀
Thanks so much for putting this together! It's been super helpful!
Thank you. 7 will definitely be one of my favorites from now.
Cool! I didn't know about 2., 4., 5. until now.
Great post
When dealing with large files, I tend to use the
Collapse All
shortcut a lot to quickly navigate to the required function.code.visualstudio.com/docs/editor/...
What could also be handy for programmers, are the commands for word part selection/deletion which unfortunately are not set (hard to standardize, definitely across OSes). When adding an ALT to all commands compared to the word selection/deletion commands, this has typically side affects with the OS navigation (e.g. desktop switching). Has anybody find a good key combination for this which is logical? Thanks!!
Command/CTRL + Shift + L - select all the occurrences of the word/selection immediately