官术网_书友最值得收藏!

Editing and code navigation in VS Code

While writing code, developers are often working with several files at the same time. Quickly navigating between files or within the same file is an important feature.

VS Code offers multiple options for code navigation—let's explore them one by one.

Go to line

To move the cursor to a particular line and column, use the Goto (:) Line command, as illustrated in the following screenshot:

Figure 1.43 – Using the command palette to move cursor to a line and column

Go to symbol

To show the symbols used in your code and to navigate directly to a selected symbol, you can use Go to Symbol (@) in a File.

Also, while you are traversing, VS Code will highlight the code section, as illustrated in the following screenshot:

Figure 1.44 – Using the command palette to jump to a section of code

In the case of JavaScript, the command palette will show methods, as illustrated in the following screenshot:

Figure 1.45 – Jump to code section in a JavaScript example

Using commands for navigation

Here are some useful commands for quick code navigation:

  • Ctrl/Command + F12: Use this command to select an object and jump to its implementation.
  • Ctrl/Command + Shift + F12: This is a quick way to peek into an implementation. The pop-up window also allows code editing. This is illustrated in the following screenshot:

Figure 1.46 – Peek into an implementation

The preceding screenshot shows an example where the ProductDetailComponent implementation is open in Quick Peek mode.

Navigating between files

VS Code provides multiple options for navigating between different files. Let's assume you have a bunch of files open in your editor. To select a particular file from currently opened files, hold Ctrl and then press Tab. VS Code will open a list of files, and you can move your selection by holding Ctrl and pressing Tab. An example list of files can be seen in the following screenshot:

Figure 1.47 – Files listed for navigation

Apart from using Ctrl (hold) + Tab, you can also sequentially switch between multiple files opened in the editor.

Use Alt/Option + Right Arrow or Alt/Option + Left Arrow to switch from one file to other opened files.

Commenting code

Last but definitely not least, how to quickly comment and uncomment code by using the following keyboard shortcuts:

  • Ctrl/Command + K then C: Use this command to comment a line.
  • Ctrl/Command + K then U: Use this command to uncomment a line.
主站蜘蛛池模板: 南溪县| 仪征市| 乌拉特中旗| 原阳县| 石阡县| 文化| 肇州县| 沾化县| 津市市| 册亨县| 修文县| 张掖市| 马公市| 方正县| 镇赉县| 通化市| 张家川| 广宗县| 无极县| 三都| 九台市| 石景山区| 米泉市| 文昌市| 孙吴县| 巩义市| 长海县| 都匀市| 汾西县| 宣汉县| 泽州县| 洛川县| 蒙城县| 韩城市| 界首市| 民勤县| 杭州市| 资源县| 碌曲县| 长治市| 循化|