Best VS Code shortcuts to write code more efficiently

In this article, you will find some very useful keyboard shortcuts that aim to make writing code in VS Code more easily, quickly and safely.

These shortcuts apply to MAC users, but there is also a list for Windows and Linux users.

You can find even more tips and tricks in the official VS Code documentation:

> https://code.visualstudio.com/docs/getstarted/tips-and-tricks

Stay tune ! There is a bonus at the end !

Moving around the code

Go to Beginning of Line: CTRL + A

Go to End of line: CTRL + E

Go to Beginning of code (first character) in this line: CMD + ←

Go to End of code (last character) in this line: CMD + →

Go to Beginning of file: CMD + ↑

Go to End of file: CMD + ↓

Moving code around !

Move an entire portion of code (line or block) up / down

ALT + ↑

ALT + ↓

Selecting more quickly !

CTRL + SHIFT + E

CTRL + SHIFT + A

ALT + SHIFT + →

ALT + SHIFT + ←

My favourite by far ! Make your life so easy

CMD + ALT + ↑

CMD + ALT + ↓

Imagine a code block with 5 occurrences of the variable server

You want to change the name of this variable from server to httpServer

The code block is (let’s say) 20 lines long, and the server variable is located at random places.

You could go with the mouse click trick mentioned above, by clicking in front of every occurrence of server while holding SHIFT key.

But there is much faster !

CMD + D

  1. Click on the variable name
  2. CMD + D (first time): it will copy the name in the search field
  3. CMD + D : it will put the cursor in front of the next occurrence
  4. CMD + D : x2, x3, x4… as many times as you need to select
  1. CMD + F : this will display the search field
  2. Enter the keyword you are looking for
  3. ALT + Enter: this will put the cursor in front of every occurrence of the word

Inserting !

Insert a comment / Commenting a line of code

CMD + /

Deleting !

What a better feeling that deleting code !

But how complicated it becomes when you have to delete specific lines, or specific portions in a line.

Have you ever experience the slow feeling, where you have to highlight manually what you want to delete?

Here are some ways to make it faster.

CMD + DEL (delete char, backspace)

CTRL + K

If your cursor is positioned in the middle of the code, it will delete everything on the left.

If your cursor is positioned at the beginning of the line, it will delete the entire line.

CMD + DELETE

If your cursor is positioned in the middle, it will delete everything on the right.

If your cursor is positioned at the end of the line, it will delete the entire line.

ALT + DEL

CMD + X

In a line of code, whether your cursor is positioned at the beginning, in the middle, or at the end, this will delete the entire line.

Duplicating / Copying

SHIFT + ALT + ↑

This will copy the line of code where your cursor is positioned, and insert it above.

SHIFT + ALT + ↓

This will copy the line of code where your cursor is positioned, and insert it above.

Juggling between files

CMD + ALT + ←

CMD + ALT + →

If you have the following 3 files opened in this order:

  • client.c
  • server.c
  • command.c
  • etc…

CMD + 1: switch to client.c

CMD + 2: switch to server.c

CMD + 3: switch to command.c

CMD + n…: etc…

Moving inside VS Code !

CMD + J

CMD + B

CMD + SHIFT + P

Quickly open a file

CMD + P

Very useful when you are working on a big project with a lot of files.

  1. CMD + P
  2. Type the file name in the search field that appear

Change Language

CMD + K M

Zen Mode

For those who like to write code distraction free !

CMD + K followed by Z

Mouse Tricks !

Here are some good tricks

Switch between opened files: hold SHIFT + scroll) (your mouse pointer should be over the file tabs area)

Open file in new tab: scroll click

Open file on right side (right split window): hold ALT + click

Scroll code horizontally: hold SHIFT + scroll (your mouse pointer should be over the code field)

hold ALT + click

Full Stack Developer, Web / Mobile and Blockchain. https://github.com/CJ42

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store