VS Code is a very popular editor in the programming world. Whether I’m writing Vue, Python, Java, or MarkDown, I use it for editing, and of course, the Vim plugin. When writing code, it is often used to format code, and while many actions can be done through buttons on the menu, it is important to keep its shortcuts in mind for efficiency.

Here are 15 shortcuts THAT I use frequently to greatly improve your editing:

0. Start VS Code from the command line

Start VS Code, press Command+Shift+ P (Mac, Ctrl+Shift+ P for Win or Linus), type shell to select the install Code Command. As shown below:

Then, if you want to open the current directory with VS Code, you can do it on the terminal:

code .
Copy the code

This is useful when you use a terminal and want to open a directory in VS Code, or Code {path} to open the corresponding path.

1. Search for the file and open it.

Shortcut:

  • Mac: Command + p
  • Windows/Linux: Ctrl + P

Navigation between files is a very common need to edit a file at the same time, need to synchronize the modification of another file, at this time the most efficient is to enter the file name fuzzy search and then enter open, the shortcut key after pressing the file name enter can open the corresponding file, much faster than the mouse selection.

2. Select all matches at one time and modify them at one time

Shortcut:

  • Mac: Command + Shift + L
  • Windows/Linux: Ctrl + Shift + L

First select or search the content to be modified, and then press the shortcut key, all matched content will be selected, and then modify it, which is equivalent to modify all matched content, do not need to copy in search and replace, wySIWYG, very convenient.

3, one by one to select matching, one-time modification

Shortcut:

  • Mac: Command + D
  • Windows/Linux: Ctrl + D

Select or search need to modify the contents of the first, and then press the shortcut key, choose the contents of the first match, press it again, will add the content of the next match, until you choose you need to modify the content, and then modify it, is equivalent to modify all the selected content, compared with a content, you can choose you want to match the content of the range.

4, undo the last selection match, is the reverse operation of shortcut key 3

Shortcut:

  • Mac: Command + U
  • Windows/Linux: Ctrl + U

When you select multiple matches, you can press this shortcut key to undo the selection, which is the reverse of shortcut key 3.

5. Select the entire row

Shortcut:

  • Mac: Command + L
  • Windows/Linux: Ctrl + L

This is very much like Vim’s Visual mode, where you press V and then J to select a whole line of text.

Press this shortcut key to select the entire line of the cursor, and press again to append the next line.

6. Jump to the specified line

Shortcut:

  • Mac: Ctrl + G
  • Windows/Linux: Ctrl + G

This shortcut conflicts with the Vim plugin, because Vim is so easy to jump to a specified line: in command mode, you can jump to a colon and a line number.

Press the shortcut key, enter the line number and press Enter to jump to the corresponding line number.

7. Close all open tabs

Shortcut:

  • Mac: Command + k + w
  • Windows/Linux: Ctrl + K + W

Open too many files and create tabs just like a browser. If you want to close them all, press this shortcut and the whole editor will be clean.

Block comments.

Shortcut:

  • Mac: Shift + Option + A
  • Windows: Shift + Alt + a
  • Linux: Ctrl + Shift + a

This is very simple, is to select a piece of code, press the shortcut key, the code can be commented out in the way of block comment.

9. Collapse/expand code.

Fold shortcut key (left middle bracket) :

  • Mac: Command + Option + [
  • Windows/Linux: Ctrl + Shift + [

Expand the shortcut keys (left brackets) :

  • Mac:Command + Option + ]
  • Windows/Linux: Ctrl + Shift + ]

10. Move rows

shortcuts

  • Mac: Option + up/down
  • Windows/Linux: Alt + up/down

11. Open the terminal

shortcuts

  • Mac: Ctrl + `
  • Windows/Linux: Ctrl + `

12. Split Windows

shortcuts

  • Mac: Command + \
  • Windows/Linux: Ctrl + \

Split window can compare files, also can compare the same file in different locations, very convenient programming.

13. Format your document

shortcuts

  • Mac: Shift + Option + f
  • Windows: Shift + Alt + f
  • Linux: Ctrl + Shift + i

Usually we enable extensions or configuration Settings to format the document when we save, but sometimes we like to control when we format the document. That’s where this command comes in. It allows us to format the current document according to the configured Settings.

14. Copy the selection below or above

shortcuts

  • Mac: Option + Shift + up/down
  • Windows/Linux: Shift + Alt + up/down

Using this command, you can copy the selected code above or below the current code. For example, if two functions have almost the same function, you can use it to make a quick copy at the bottom, and then make some changes to make a new function.

15. Open or hide the sidebar

shortcuts

  • Mac: Command + b
  • Windows/Linux:

You can use this command to toggle the sidebar so that you have more screen real estate when looking at your code.

The last

This article introduces 15 common and effective VS Code shortcuts that can greatly improve your coding efficiency. Of course, there are other useful shortcuts, such as Command+Shift+ F (Mac) for searching for file contents, Command+Shift+ P for searching for commands, Command+ / for toggling line comments, and so on.

Thanks for reading. Again to ask for attention, if you think the content is good, please pay attention to or share to your friends, thank you for your support