Visual Studio Code is a lightweight yet very powerful source code editor which runs on your desktop and is available for Windows, macOS, and Linux. It comes with built-in support for JavaScript, TypeScript, and Node.js and has a rich ecosystem of extensions for other languages and runtimes (such as C++, C#, Java, Python, PHP, Golang).
Extensions, Shortcuts, Debugging, Customizations, In-built cloud support, Containers, Git integration, etc. are some of the few pigeons in the hat of VS Code. Out of all, now we will take a crucial step in order to become a VS Code power user, that is to get used to some important and basic keyboard shortcuts of VS Code and to lessen the use of the mouse so that while coding it improves our productivity and speed.
Below are the Important Keyboard Shortcuts for VS Code:
Commands | Windows/Linux | MAC |
---|---|---|
Delete Line | Ctrl + Shift + K | Cmd + Shift + K |
Copy Line Up or Down | Shift + Alt + Up arrow or Shift +Alt + Down arrow | Opt + Shift + Up arrow or Opt + Shift + Down arrow |
Global Find | Ctrl + Shift + F | Cmd + Shift + F |
Format Document | Ctrl + Shift + i | Cmd + Shift + i |
Toggle Block Comment | Ctrl + Shift + / | Cmd + Shift + / |
Command Palette | Ctrl + Shift + P | Cmd + Shift + P |
Toggle Line Comment | Ctrl + / | Cmd + / |
Trigger Suggestion | Ctrl + Space | Cmd + Space |
Toggle Sidebar | Ctrl + B | Cmd + B |
Multi Select Cursor | Ctrl + D | Cmd + D |
Quick Open | Ctrl + P | Cmd + P |
1. Delete Line
Windows/Linux: Ctrl + Shift + K Mac: Cmd + Shift + K
Quickly deleting a whole line using a single command is a very satisfying thing to do, isn’t it? Just use the above-given command to delete the whole line, you can be anywhere on the line it doesn’t matter, below is a short demo.
2. Copy Line Up or Down
Windows/Linux: Shift + Alt + UpArrow or Shift + Alt + DownArrow Mac: Shift + Opt + UpArrow or Shift + Opt + DownArrow
Many times we need to copy the very same line-up or down, for which selecting the whole line using the mouse and then copying it up or down would be too much work to do, we can just use the above-given command to do the same, below is a short demo.
3. Global Find
Windows/Linux: Ctrl + Shift + F Mac: Cmd + Shift + F
Finding anything in a humongous folder is a tedious task, to find anything in the current working directory, we can use the above-given command, below is a short demo.
4. Format Document
Windows/Linux: Ctrl + Shift + i Mac: Cmd + Shift + i
Most of the time, we don’t give attention to indention spacing and current format to write of that particular language, also you would not even think to format a big file, here the Format Document shortcut comes to our rescue, use the above-given command to format your file, you need to initially set a default format after which this shortcut is very useful, for most languages Prettier works easily, below is a short demo.
5. Toggle Block Comment
Windows/Linux: Ctrl + Shift + / Mac: Cmd + Shift + /
Just like line comment, block comments are equally important, we use the above-given command to initiate a block comment, to uncomment use the very same command, below is a short demo.
6. Command Palette
Windows/Linux: Ctrl + Shift + P Mac: Cmd + Shift + P
Command Palette is the heart of VS Code, from here you can access anything and everything inside VS Code. Just press the required command to invoke the command palette and type which command or what you want to do, this is the one-stop solution to any problem related to finding anything in Vs code, below is a short demo.
7. Toggle Line Comment
Windows/Linux: Ctrl + / Mac: Cmd + /
Commenting in any language requires no introduction, it is very helpful so in order to comment on a line just use the above-given command, you need not be on the right-most side in order to comment on the line you can be anywhere on the line, and press the required command to comment the line out, to uncomment use the very same command, below is a short demo.
8. Trigger Suggestion
Windows/Linux: Ctrl + Space Mac: Cmd + Space
Sometimes in order to see check out the valid parameter and trigger a suggestion for the next keyword we can use the Trigger suggestion shortcut, suggestion box covers too much of the screen to quickly turn it off we can use the above-given command, below is a short demo.
9. Toggle Sidebar
Windows/Linux: Ctrl + B Mac: Cmd + B
Sometimes sidebar having dozens of files and folders can be intimidating when you want to focus, just toggle the sidebar to hide it by pressing the required command. To expand it again use the same command, below is a short demo.
10. Multi Select Cursor
Windows/Linux: Ctrl + D Mac: Cmd + D
Suppose in a file we have multiple instances of a variable, function, or method, for some reason we have to rename that particular variable, function, or method which would be a lengthy process, and also we might miss some instances which would be a horrific case if the file size is humongous.
Multi Select Cursor comes to the rescue in this situation, just select that variable, function or method, or anything that you want to rename and press the required command it will select one instance every time you type the command, after selecting all the instances you can rename it as of your wish, below is a short demo.
11. Quick Open
Windows/Linux: Ctrl + P Mac: Cmd + P
To access any file we use quick open in Vs code, this allows us to quickly access the files inside a current working directory, it shows previously accessed files in the suggestion box after being invoked, below is a short demo.
Note: You can also customize the shortcuts to your desired combination of keys. Just open the keyboard shortcuts in settings menu and set the desired key combination to the respective shortcut.