⏲ Time is running out to sign up for our last BOOTCAMP cohort of 2023. Find out more and apply
Visual Studio Code is a highly versatile and powerful text editor that is used by developers all around the world. One of the key aspects that makes VS Code so popular is its speed and efficiency that it brings developers, which is largely due to the vast array of keyboard shortcuts available. By utilising these shortcuts, developers can perform various tasks quickly and easily, allowing them to maximise their productivity.
In this blog post, we will take a look at some of the most useful keyboard shortcuts for Visual Studio Code that every developer should know. Note that this guide is tailored towards Mac users, but - where referenced - Linux and Windows users can simply swap the Command / Cmd key for Ctrl. Whether you are a beginner or a more seasoned developer, these shortcuts will help you to save time and effort in your day-to-day coding activities.
One of the most powerful features in Visual Studio Code is the Command Palette. This feature allows you to quickly search and run commands without having to navigate through the menus. To open the Command Palette, press Command ⌘ + Shift ⇧ + P. From here, you can search for any command, and when you find what you're looking for, simply press Enter to run it.
When the Command Palette opens, you can navigate up and down the options with the Up and Down arrows. You can even see the keyboard shortcuts (if any) to run that command again
If you need to quickly open a file in your workspace, the best way to do this is by using the Quick File Search feature. To open this feature, press Command ⌘ + P. This will bring up a search bar, where you can start typing the name of the file you want to open. As you type, Visual Studio Code will provide suggestions based on your workspace, and you can simply select the file you want to open from the list.
When the Quick File Search dialog pops up, you can start typing to narrow down the results. Use the Up and Down arrows to select the file you wish to open and hit Enter
When you have multiple tabs open in Visual Studio Code, it can be a bit challenging to navigate between them. However, there are a few keyboard shortcuts that can make this task much easier. To navigate between recently used tabs, hold down Ctrl + Shift + Tab, and keep pressing the Tab key until you find the right tab, at which point you can release the Tab key and subsequently the Ctrl + Shift keys. Additionally, you can jump directly to a specific tab by pressing Ctrl + 1 to Ctrl + 9, depending on the tab number - based on the order in your tab list - you want to open.
Switching between tabs with Ctrl + Shift ⇧ + Tab
One of the great things about Visual Studio Code is that it allows you to customise your own keyboard shortcuts. If there's a specific command you use frequently, you can assign a keyboard shortcut to it to make it even easier to access. To open the Keyboard Shortcuts editor, press Command ⌘ + K + S. From here, you can search for commands and assign keyboard shortcuts to them as desired.
Change and add new shortcuts for commands in the Keyboard Shortcuts settings menu
Visual Studio Code has an integrated terminal that allows you to run commands directly from within the text editor. To open the terminal, press Ctrl + Shift ⇧ + `. This can be particularly useful if you need to run a command that you don't want to run in your regular terminal window.
VS Code has it's own built in terminal
When you're working with code, it's often necessary to select text. There are a few keyboard shortcuts that can make this task much easier. For example, to select text word by word, press Command ⌘ + Shift ⇧ + Left/Right Arrow. Additionally, you can move the current line up or down by pressing Alt + Up/Down Arrow.
You can conveniently select around blocks of code with the Command ⌘ + Shift ⇧ + L/R arrow key combination
Use Alt and the Up / Down arrow keys to move a selection up or down your code
If you need to select multiple occurrences of the same text, Visual Studio Code has a multi-selection feature that can make this task much easier. To select the next occurrence of the selected text, press Command ⌘ + D. This will allow you to select multiple instances of the same text, which can save you a lot of time when making changes to your code.
Another essential set of keyboard shortcuts for Visual Studio Code is Undo and Redo. To undo the last action, press Command ⌘ + Z. To redo the last undone action, press Command ⌘ + Shift + Z. These shortcuts can be a lifesaver if you accidentally make a mistake in your code and need to revert it. Bonus: These commands also work in a number of other applications for the same purpose.
When you're working on a project, you might want to temporarily comment out some code to see how it affects the rest of the project. Visual Studio Code makes this process simple with the commenting out shortcut. To comment out the selected line(s) of code, press Command ⌘ + /.
You can comment out one or many lines in one go with the commenting out shortcut
Sometimes you may need to insert a new line above the current line in Visual Studio Code. To do this, simply press Ctrl + Shift + Enter. This can be useful if you need to add a new line of code above the current line without having to navigate to the beginning of the line.
In conclusion, these are just a few of the most useful keyboard shortcuts for Visual Studio Code. By utilising these shortcuts, you can save a lot of time and effort in your coding activities, making you more productive and efficient. There are many more shortcuts available in Visual Studio Code, and remember: you can find a complete list of commands and their shortcuts in the Command Palette (Command ⌘ + Shift + P). Happy coding!