Code

Keyboard Shortcuts in VS Code: Which Ones to Use and Why

Keyboard Shortcuts in VS Code: Which to Use and Why

Training program with a guarantee Job openings: "Web Development Specialist"

Learn more

Keyboard shortcuts make developers' jobs much easier, saving them time. Visual Studio Code also includes such combinations. Users can also create their own, but for most, especially beginners, the standard options are sufficient. This is especially true for those who are faced with a multitude of settings and may get confused.

Let's look at the most useful resources for those just starting out in layout. Read on and feel free to experiment right away.

1. Invoke a search

Typical task

You need to find all elements with the "link" class and apply styling to certain ones, while simultaneously adding a new class.

What to do

To search for the required information on the page, use the keyboard shortcut Ctrl + F if you're on Windows, or ⌘Cmd + F if you're on macOS. Then, enter the search text, and you'll see all the matching results. Then you just have to navigate between them using the navigation arrows.

2. Formatting comments in the code

Situation

If you need to add a comment or temporarily disable a certain fragment of code (for example, in order to test the functioning of other parts), you can do this.

What to do

Select the required text fragment and press Ctrl + / if you are using Windows, or ⌘Cmd + / for macOS. If nothing is selected, the line where the cursor is located will be commented out, and it can also be uncommented in the same way.

3. Go to the line with the specified number

Typical situations

  • During layout check, it became necessary to identify and correct a specific property. The browser's code inspector provides information about the path to the corresponding file, usually associated with styles, and also indicates the line number where this property is located.
  • In the program code editor, a notification appears about an error on a specific line.

What to do

To quickly jump to the desired line, press Ctrl + G (for Windows) or ⌃Ctrl + G (for macOS), then enter the line number, and you will not have to scroll the document manually.

5. Copying a string

Situation

It is necessary to quickly insert identical elements into the markup. That is, you need to create a duplicate of the line, placing it either above or below the original.

What to do

Place the cursor on the desired line, and then press the keyboard shortcut Shift + Alt + ↓ / ↑ for Windows or ⇧Shift + ⌥Option + ↓ / ↑ for macOS.

6. Bringing the listing to the desired format

Typical need

Speed ​​up the process of tidying up your code so that it becomes more organized, understandable, aesthetically pleasing, and meets your coding standards (for example, you can learn about Java style here).

What to do

Press the Shift+Alt+F key combination on Windows or Shift+Option+F on macOS.

To ensure correct formatting:

  • Please install a code formatting plugin.
  • Configure the editor according to your coding style. Also, don't forget to set the correct indentation value, which is usually 2 or 4 spaces.

Variety of data input

Multi-cursor is impressive in its functionality and significantly increases the speed of the layout designer.

Situation

You needed to place the same information in several different places at once.

To create a copy of the cursor:

  • Hold down the Alt key on Windows or ⌥Option on macOS, then left-click where you want to place the cursor.
  • To select multiple lines, press and hold the middle mouse button. As a result, a cursor will be displayed on each of the selected lines.
  • If you don’t want to constantly click the mouse, you can duplicate the cursor using keyboard shortcuts: for Windows, this is Ctrl + Alt + ↑ / ↓, and for macOS, this is ⌥Option + ⌘Cmd + ↑ / ↓.

8. Multi-level Editing

Situation

You need to make changes to the same code in several locations simultaneously.

What to do

Select the desired characters with the mouse and use the keyboard shortcut Ctrl + D on Windows or ⌘Cmd + D on macOS. Multiple clicks will add another match of the selected fragment, located further in the text. After that, you will be able to simultaneously edit all selected areas, which will be highlighted in blue.

9. Abbreviations for tags and properties

How it works

When you enter one or two characters, auto-completion begins to suggest the name of the HTML tag (along with the closing tag) or the name of the CSS property. Wait for the editor to highlight the suggested option (if several options are available, select the one you need), and then press Tab or Enter.

All available abbreviations are presented here. As you memorize them, your skills and speed of completing tasks will increase, and, believe me, this will bring great joy.

10. Shortcuts for Multi-Line Expressions

Why You Need It

To speed up the process of generating structures consisting of interrelated tags.

For example, you need to generate an unordered list consisting of four elements. Each of these elements should contain a link belonging to the link class. And all this needs to be done very quickly.

What to Do

Simply enter ul>li*4>a.link, wait until this option is highlighted (it is the only one in the drop-down list), and press Tab or Enter. The editor will automatically insert the full structure. This technique significantly speeds up the work process, although at first it may seem like something surprising.

11. Activate the terminal

It's hard to imagine a full-fledged workflow in VS Code without using the terminal.

Situation

You need to open the terminal, which will simplify the process of finding errors in the code (notifications will be displayed in the Problems section), and also allow you to conveniently interact with Git, a distributed version control system.

What to do

For Windows users, press the key combination Ctrl + `, and for macOS users, press ⌃Ctrl + `.

To summarize

Memorizing hotkeys is quite easy once you start using them. Full lists of shortcuts can be found here and here, and abbreviations are available at this link.

We hope that your work in VS Code will be easy and enjoyable!