If you’re anything like me then you might find yourself reaching for the mouse at every opportunity. But maybe you’ve been watching your favourite developers on YouTube and seeing how they navigate through their code using nothing but the keyboard. This was the situation I found myself in and I realised that I wanted to master the keyboard – so I took some time to learn the shortcuts. Apart from the obvious benefit of looking cool, relying less on the mouse and more on the keyboard is likely to increase your coding speed. As you know time is money, so let’s jump in and learn some of the best keyboard shortcuts for VS Code.

I’m only going to cover the shortcuts that I use the most, I’ve provided a cheat sheet at the bottom of this article that summarises the shortcuts I discuss in this article. If you’d like to see a full list of VS Code shortcuts, you can press CTRL + K followed by CTRL + S whilst in VS Code to bring up a list of all the shortcuts. If you just want to see my favourites then keep reading.

Comment out code block
WINDOWS: Highlight text + CTRL + /
MAC: Highlight text + ⌘ + /
The shortcut I love the most is to comment out large blocks of code quickly. This was one of the first shortcuts I learned because it really is the most useful. Commenting out code is an essential part of my debugging process, so I really couldn’t live without this one.

Indent code from right-to-left
WINDOWS: CTRL + [
MAC: ⌘ + [
Good code needs proper indentation, personally I like to use TAB to indent my code, but what happens when you indent too far and you want to move the code block in the other direction (from right to left). This is where CTRL [ comes in. I use this one less now that I have the Prettier extension which automatically formats my code but it’s still a useful one to know.

Highlight all code in the file
WINDOWS: CTRL + A
MAC: ⌘ + A
This is a nice and easy one to remember which is also extremely useful to know. Selecting all the text In a file at once can save you a lot of time if the file is quite large.

Highlight all code in that line
WINDOWS: CTRL + L
MAC: ⌘ + L
This is a quick way to highlight the line of code that your cursor currently sits on.

Move a line of code up or down
WINDOWS: Alt + UP/DOWN key
MAC: ⌥ + UP/DOWN key
I use this one a lot to rearrange the order of my lines of code. I mostly use it to move one line at a time but it can also move entire blocks of code if you highlight the text first.

Search all files in VS Code
WINDOWS: CTRL + SHIFT + F
MAC: ⇧ + ⌘ + F
This is a great one that I just recently learned. If you have a load of files and folders in VS Code and you are looking for something specific you can use this shortcut to quickly find it. I wish I had known about this one earlier.

Multi cursor on matching code
WINDOWS: Highlight text + CTRL + D
MAC: Highlight text + ⌘ + D
This one is great for updating the same variable name or class name throughout the entire code block or file. The command will place multiple cursors on code that matches the code you have highlighted, you can then edit them all at once.

Multi cursor
WINDOWS: Alt + Click
MAC: ⌥ + click
This one is cheating a little because it involves the mouse but it’s a useful shortcut so I’m including it anyway. It allows you to create multiple cursors wherever you want in the file.

Go to new file
WINDOWS: CTRL + P
MAC: ⌘+ P
This shortcut will bring up the dropdown menu with all your files so that you can quickly navigate to a new one. Definitely a good one to know

Navigate through your open files
WINDOWS: CTRL + Tab
MAC: ⌃ + Tab
This is an essential one to know if you are going to rely less on your mouse. Keep holding CTRL and hit Tab to navigate through each open file. Hitting SHFIT + Tab will go in the opposite direction.

Cheat Sheet

  • Highlight text + CTRL + / || Highlight text + ⌘ + / - comment out code block
  • CTRL + { || ⌘ + [ - indent code from right-to-left
  • CTRL + A || ⌘ + A – highlight all code in the file
  • CTRL + L || ⌘ + L – highlight all code in that line
  • Alt + UP/DOWN key || ⌥ + UP/DOWN key – move a line of code up or down
  • CTRL + SHIFT + F – || ⇧ + ⌘ + F - search all files in VS Code
  • Highlight text + CTRL + D || Highlight text + ⌘ + D – multi cursor on matching code
  • Alt + Click || ⌥ + click – multi cursor
  • CTRL + P || ⌘+ P – go to new file
  • CTRL + Tab || ⌃ + Tab – navigate through your open files

    That covers all of the shortcuts I use on a regular basis. I’ve only scratched the surface of the shortcuts available and would love to hear more if any of you have some useful ones that you use regularly - please Tweet me if you do.