We all know about the Visual Studio Code (Also known as VS Code) editor. It’s one of the most popular coding editors. And my most favorite editor. Microsoft created this editor, and it’s completely free.
There are so many reasons why it is so popular. But this is not the purpose of this blog. This blog is about to most useful VS Code shortcuts. I hope these shortcuts will help you to improve your productivity when you are going to write code in VS Code.
There are so many VS Code shortcuts, but I am not going to cover all of those. I am going to cover the most useful shortcuts from them. I hope you will find some helpful shortcuts. So let’s see. Ordering is just random.
Often we want to modify our editor as per our preferences. In settings, we will find tons of options for that. Changing theme, formatting text, and other editor’s behavior we can change. To open the settings option using the keyboard:
CTRL + ,
CMD + ,
Open Integrated Terminal
There is an integrated terminal in VS Code. Often we have to open the terminal to run commands. We can open the terminal by clicking from the editor’s view menu. But it’s faster to open using the keyboard rather than using the mouse. To open using the keyboard:
CTRL + `
CMD + `
Open A File
Most of the time, we work on multiple files when we work on a project. Sometimes It’s tedious to navigate from one file to another file by clicking when the file is in another directory. But we can do it very fast using the VS Code shortcut. If we use this shortcut, it shows us a list of all the files from our opening project. We can open a file, search files, navigate using the up and down key from that files list. The keyboard shortcut is:
CTRL + p
CMD + p
Often we need to work on multiple files at the same time. To do that, we can split up the files into a different window. To move the current working file into a different window, we can use:
CTRL + \
CMD + \
Traversing Through The Open Files
We open multiple files in our editor very often. To work on those files, generally, we have to click on the file tab if we don’t use the keyboard shortcut. We can do it easily using a keyboard shortcut without moving our hand into the mouse. For that, the shortcut is:
CTRL + TAB
CMD + TAB
We can also traverse backward using:
CTRL + SHIFT + TAB
CMD + SHIFT + TAB
Close A File
If we want to close the current opening file in the VS Code, there is a less time-consuming way to do it than using a mouse. To do this, we can use this shortcut:
CTRL + w
CMD + w
Commenting is very helpful when we write code. It helps us and also will help those who read our code. Often we need to comment on our code also. Commenting styles vary from language to language. In the VS Code, we don’t need to worry about that. To do this, we have to point the cursor on that line and use the shortcut. If we want to use multiline comments, just select the whole code or text, then use the shortcut. The shortcut is:
CTRL + /
CMD + /
We can also undo the comment using the same shortcut.
Duplicate Line or Block
Suppose we need to duplicate a line or a specific block of code in the below or above. What we do if we don’t use a keyboard shortcut? Generally, we will use copy and paste. But we can do it more easily using a shortcut. The shortcut is:
SHIFT + ALT + UP/DOWN
SHIFT + OPTION + UP/DOWN
If we want the duplicate in the below, we will use the DOWN key otherwise UP key.
When we want to write the same word or text in different lines, this shortcut may help. For that, we have to press ALT+ Right-click on that line. We can create cursors by pointing on the line using the shortcut as many as we want.
ALT + Right Click
OPTION + Right Click
This one is one of the most helpful. In the command palette, we can find so many options for our VSCode. If we forgot any command or shortcut, there is an option for search. There is a huge list of that. Also can navigate the list using the Up and Down key. To open the command palette using the keyboard shortcut:
CTRL + SHIFT + p
CMD + SHIFT + p
For search in the opening file, use
CTRL + f. Use
CTRL + h if you want to search and replace any text or code in the opening file. And for toggling the sidebar, use
CTRL + b.
Keyboard shortcuts are always helpful. If we can use keyboard shortcuts wisely, it will definitely increase our productivity.
There are also many useful shortcuts that I did not cover. But if you are a beginner, the above mentioned those will come in handy even if it is a little bit. Happy Learning.