As programmers, we are always spending most of our time in IDEs and editors, be it coding, formatting, or interpreting the code. So, It is always a better practice to make minimal use of a mouse. Ideally, you should not touch the mouse while coding because shifting to and fro from the mouse and keyboard could consume a lot of your time in the long run. So even if you find it difficult to remember the shortcuts initially, you should persist using the keyboard and take that extra bit of time. Before you know, it is embedded in your muscle memory, and it feels ridiculously easy to work with a keyboard alone, mostly.
VS Code is a powerful editor that comes with tons of cool features. And one of the coolest features is Keyboard shortcuts, a lot and lots of them which are very easy to use and remember. You also have the option to create your shortcuts or change any of the existing shortcuts. These shortcuts are particularly more useful where you are working on a large project with many files, and it often requires you to move to and fro between the files. So here are the 25 most productive shortcuts which I find useful in my everyday work. As I mentioned, there are so many shortcuts, so this list is by no means exhaustive, but these are the shortcuts that drastically increases your output if you imbibe them in your routine.
Best 25 Visual Studio Code shortcuts to remember.
Ctrl + P – Opens up a file search within the project.
Usage: This is probably the essential shortcut for VS Code. You can search and navigate to any file within your project using this shortcut. Instead of opening a file, if you want to go to a specific line, write ‘:’ followed by the line number, and you can navigate to that line number of the active window. You can also navigate to symbols within the active file by writing `@’ followed by the symbol name.
Ctrl +Shift + P – Opens up a Command Palette
Usage: It is also one of the most useful shortcuts for the VS Code, especially when you are beginning to learn by heart these shortcuts. Command palette is used to perform several different actions like renaming a symbol or formating the documents or reloading a window. You can search through actions, and it displays the action along with shortcuts for that action so that next time when you want to perform that action, you can do it only by pressing the shortcut keys. For example, you can format the document, as shown below.
Ctrl + Shift + ` – Opens an integrated Terminal
Usage: VS Code comes with an integrated terminal. Using this shortcut creates a new terminal window inside the VS Code, keeping the previous terminal window running. It is useful when you are running multiple servers. You can also split the terminal window side-by-side by pressing Ctrl + Shift + 5. So both terminal outputs are visible.
Bonus: When you are working on a project it often requires you to toggle between editor and terminal, you can do this without making use of the mouse by pressing Ctrl + `
Ctrl + K,Ctrl + C – Comments a selected line of code
Usage: This shortcut is used to comment out single or multiple lines of code. First, you need to select the lines you want to comment and then press this shortcut keys to comment that code. To uncomment the commented lines, select the code to uncomment and then press Ctrl + K, Ctrl + U.
Bonus: To quickly toggle a block of comment, you can use Ctrl + Shift + A
Ctrl + Shift + C – Opens an external Terminal window in the project location.
Usage: Sometimes, the integrated terminal is difficult to use. In that case, if you want to open an external terminal in the same project folder that you are working on, you can simply use this shortcut, and you can find a beautiful terminal window ready.
Ctrl + T – Go to a symbol anywhere in the project.
Usage: If you want to go to a specific function in any of the files in your project, you can simply press this shortcut key and search for that function or class or variable and go directly there. It is so much useful when there are large files, and you are working between multiple files. You can also do the same by pressing Ctrl + P and writing ‘#’ followed by the symbol name.
Ctrl + Shift + O – Go to a symbol within the active file.
Usage: With this shortcut, you can go to any symbol within the open file. It could be useful in case you are working in a large file with lots of lines of code. You only need to type the name of the symbol after pressing this shortcut key. You can also do the same using Ctrl + P and writing ‘@’ followed by a symbol name, but as you use it, you can realize that this is too long as compared to the given shortcut
Ctrl + G – Go to a specific line inside the active file
Usage: This comes in handy when you are working in a large file with thousands of lines of code. Sometimes, it is difficult to navigate within such huge files. So you can just remember the line around which you want to go, press this shortcut and enter the line number, you can navigate to that line of the active window. It is done using Ctrl + P, then writing ‘:’ followed by the line number.
Ctrl + Alt + R – Open containing folder of the selected file or directory
Usage: When you want to go to a file location of a particular file in the file manager, you need to select the file in the file manager and press this shortcut to open the folder containing that file. Make sure that the project manager window is in focus when using this shortcut.
Ctrl + K, Ctrl + Q – Go to last edit location
Usage: This is a handy shortcut that you can rarely find in this kind of article, but I have personally used it a lot. Say, for example, you are editing somewhere in a file, and you need to go to another file and make a change there, and then you need to come back to where you were working. You don’t need to remember anything, just press this shortcut, and it takes you back to your last edit location, and just like that, you can start working from where you left.
Ctrl + Alt + C – Copies the path of an active file
Usage: If you want to fetch the path of the file you are working on, just make sure the project manager is in focus and press this shortcut to copy the complete path of the file.
F2 – Rename Symbol
Usage: You often misname a symbol initially, which you want to change later, and this becomes a tedious task as you need to find each string and see that each string with that name is referring to that symbol or not. VS Code provides a separate feature for that called rename symbol. Instead of matching the string, it finds the underlying references and changes the name of that symbol. Some languages even support renaming a symbol throughout the files.
Ctrl + W – Close an active file window
Usage: This shortcut can help you a lot in achieving your goal of not using a mouse. While working on a big project, we tend to open lots of files, but only some of them we want open. So we can use this shortcut and close that file after using it and keep our workspace clean
Ctrl + Shift + E – Shows an Explorer/Project Manager
Usage: This brings into focus the explorer or the project manager, and you can make file search or navigation after getting explorer into the focus. While working in an editor, if you want to open a containing folder of an existing file, you can use this shortcut to focus explorer and then press Ctrl + Alt + R to open the folder containing the file.
Ctrl + K, Z – Zen mode
Usage: What VS Code calls Zen mode is hiding all the UI except for the editor view, including status bar, activity bar, sidebar, and panel. It allows you to focus only on coding in a full screen and center align the file. You can escape the zen mode by pressing Double Escape. This feature restricts you from defocusing in hundred other things going on in the editor
Ctrl + K, Ctrl + S – Opens a Keyboard Shortcuts list in a window.
Usage: If there is only one shortcut from this list that you can remember then this is the shortcut to remember because pressing this opens up a list of keyboard shortcuts where you can find every shortcut mentioned in this article and plenty others
Ctrl + , – Open user settings of VS Code
Usage: VS Code offers a lot of customizable settings options as per your personal preference, which you can make in user settings JSON file or material theme. If you are someone who continually likes to play with the settings, this shortcut comes in handy for you.
Ctrl + B – Toggles Sidebar
Usage: This shortcut lets you toggle the sidebar in and out in the editor workspace. If you do not always need to use the explorer or other sidebar feature you can toggle to get rid of it and again press this shortcut to bring it back when needed
Ctrl + Right arrow/Left arrow – Go to the next word.
Usage: I added this shortcut to the list keeping in mind that this list is for someone who is making minimal use of a mouse, so this shortcut could especially come in handy. You feel compelled to use a mouse to go to the middle of a long line in the code but not anymore. You directly go to the next word in the line by using this shortcut. This shortcut can help you navigate faster.
Ctrl + Shift +F and Ctrl + F and Ctrl + H – Project search
Usage: You must be knowing that if you want to search anything through a file, you can use Ctrl + F, which is a standard key for finding something. But by using this shortcut, you can search through any word or string within the entire project.
You also get the feature to include specific files in the project or exclude specific files in the project. Moreover, you can replace found occurrences throughout the entire project by using Ctrl + Shift + H
Ctrl + D and Ctrl + F2 – Add selection to next find match
Usage: This shortcut can be pretty useful to select a word with the next to find a match. Suppose you have selected a word, and you use this shortcut, it can find the next occurrence of the selected word in the file, and then you can simultaneously make changes, and it takes effect in both the words. If you want to select multiple occurrences, you can press Ctrl + D multiple times.
Bonus: All the occurrences with the same name can be selected at once using Ctrl + F2, and then the changes you make can simultaneously reflect in all the occurrences in the file
F12 – Go to Definition
Usage: Go to the definition is a handy feature provided in any IDE, which takes you to the definition of the symbol where it was defined. It is often useful to examine how a particular object will behave by viewing its definition. But we rarely use a keyboard shortcut for that. Pressing this shortcut keeping the cursor on a symbol will take you to the definition of that symbol
Ctrl + Shift + \ – Go to Bracket
Usage: – This is an effortless, albeit useful shortcut. If you want to navigate to the end of the function or a loop or an if statement, similarly, you can also navigate to the start of the bracket. Put your cursor on the start bracket and press this shortcut, It will navigate you to the end of the bracket and vice versa.
Ctrl + Space – Trigger suggestion
Usage: – Although as you write a variable or a symbol name, VS Code Intellisense starts suggesting the available symbol, you can manually trigger a suggestion if you want to see the available symbol you can write. It is helpful when you are importing a library or something like that where you might not know precisely a name, and you could take help of the suggestions
Ctrl + Shift + I – Format Document
Usage: – This shortcut formats the document by your default formatter. You can set formatOnSave to true in user settings file so that it automatically gets formatted when a document is a saved but for some reason, you do not want to do that and use format as when required, this shortcut could be very useful to quickly format the currently active document.
I have tried to mention here all types of shortcut keys so that you require minimal use of a mouse, and most of your objectives can be accomplished using the shortcuts mentioned here. Some shortcuts might be standard, but I think they are necessary shortcuts when you are only using a keyboard. I know there are still a few shortcuts that are not mentioned in this list and deserve to be on the list. Let me know your favorite shortcut in the comments down below. It is important to note that you can create your shortcut as well. If you look in the VS Code keyboard shortcut list, you will find that there are a lot of unassigned shortcuts. So check that out, it might turn out to be more useful for you. I hope you enjoyed reading this. Thank you for your time.