VS Code keyboard shortcuts, tips & tricks

In this article, we will see the important shortcuts and tricks to do daily code-level work more productively.

Format document

For Mac

Option + SHIFT + F 

For Windows keyboard

Alt + SHIFT + F 

You can always right-click on any line from the file and click on the format document option.

Remove unnecessary imports | Add missing imports

For import organizations use this shortcut. If a particular import has 2 suggestions then VSCode asks you to select the appropriate import.

For Mac

Option + SHIFT + O

For Windows keyboard

Alt + SHIFT + O

Select multiple variables, types, or lines simultaneously

Sometimes we want to change multiple occurrences of similar variables, types, or lines and cannot change them one by one which is time time-consuming task. You can use the below shortcut to complete your task fast

For Mac

CMND + Press D multiple times to select the similar items

For Windows keyboard

CTRL + Press D multiple times to select the similar items

Global search

Search for a particular word in the whole folder using this command. Trick – You don’t have to copy the word every time just select the word and press the following buttons.

For Mac

CMND + SHIFT + F 

For Windows keyboard

CTRL + SHIFT + F 

Move line(s) without copy paste

If you want to move the line without copy-pasting just select the line or keep the curser on the line you want to move, press and hold the option/alt key, and then press the up/down arrow to move the line.

For Mac

option + UP ARROW // to move line upwards  
option + DOWN ARROW // to move line downwards

For Windows keyboard

Alt + UP ARROW // to move line upwards  
Alt + DOWN ARROW // to move line downwards

Copy line without selecting

Keep the cursor on the line you want to move and use CMND/CTRL + C . Now the whole line is copied to your clipboard you can paste it anywhere you want.

Go to a specific file directly

If you want to open any file directly without navigating from folder to folder just press CMND/CTRL + P

then type in your file name in the search box at the top. VS Code will start suggesting the file names select your file and you are there.

Go to a specific line

MAC

CTRL + G // then type line number in search box

Replace/change multiple occurrences in same file having similar code

  1. Select the word beside and press CMND + F
  2. CMD + Shift + L (this will select all occurrences)
  3. Press ESC
  4. do the changes in selected portion or near this word by using arrow keys for navigation
  5. Make the changes you want to do

Important extensions

  1. Git lense
  2. Language pack. For eg. for Java projects use the Java extension pack

Let me know in the comments what else you want to make the work better!

Leave a Comment