How to Permanently Enable Line Numbers in IntelliJ IDEA? – 如何在 IntelliJ IDEA 中永久启用行号?

最后修改: 2023年 9月 26日

中文/混合/英文(键盘快捷键:t)

1. Overview

1.概述

IntelliJ is a trendy integrated development environment (IDE) tool for code development. It is an intelligent code assistance that enhances code productivity and fastens development work. Additionally, it follows a structured way to organize the project directory. Also, it is used in various programming languages like Python, Java, Kotlin, Lua, and many more.

IntelliJ是一款时尚的集成开发环境(IDE)工具,用于代码开发。它是一种智能代码辅助工具,可提高代码生产率并加快开发工作。此外,它还采用结构化方式组织项目目录。此外,它还可用于 Python、JavaKotlin、Lua 等多种编程语言。

In this tutorial, we’ll learn how to enable the line number in IntelliJ in different ways. Furthermore, allowing the line to number in the project is a handy feature in writing and debugging code.

在本教程中,我们将学习如何在 IntelliJ 中以不同方式启用行号。此外,在编写和调试代码时,允许在项目中使用行号是一项非常方便的功能。

2. Enable Line Number Globally

2.全局启用线路编号

Enabling the line number is a straightforward task as it enhances code productivity and the experience for developers. Furthermore, it helps in writing code quickly and effectively. In IntelliJ, we can enable this feature globally and file-specific.

启用行号是一项简单易行的任务,因为它能提高代码的生产率,为开发人员带来更多体验。此外,它还有助于快速有效地编写代码。在 IntelliJ 中,我们可以在全局和特定文件中启用该功能。

To demonstrate, let’s first look at enabling this feature globally for all projects:

为了演示,让我们先看看如何在所有项目中全局启用这一功能:

  • Open the IntelliJ IDEA IDE
  • Click on the IntelliJ IDEA in the top menu
  • Click on Settings
  • Click on Editor > General > Appearance
  • Check the box next to Show line numbers

The above-explained entire process is visible in the GUI below:

下面的图形用户界面显示了上述整个过程:

Global

This way, we can easily enable the line number for all the projects added to IDEA. Furthermore, restarting the IDE can also ensure that the changes have been remembered.

这样,我们就可以轻松启用添加到 IDEA 的所有项目的行号。此外,重启 IDEA 还可以确保更改已被记住。

3. Enable Line Number per File

3.启用每个文件的行号<span

In IntelliJ IDEA, we can also enable a line number per file basis. Using this method, we can further control which files display line numbers in the code. To illustrate, let’s look at the steps to enable line numbers for a specific file:

在 IntelliJ IDEA 中,我们还可以按文件启用行号。使用这种方法,我们可以进一步控制哪些文件在代码中显示行号。为了说明这一点,让我们看看为特定文件启用行号的步骤:

  • Open the IntelliJ IDEA IDE
  • Pick a file from a project
  • Right-click on the left marker of the opened file
  • Select Appearance from the list
  • Check the box next to show line numbers

To illustrate, let’s look at the GUI of the above process:

为了说明问题,让我们来看看上述流程的图形用户界面:

File Basis

Enabling a line number per file basis allows developers to customize the code settings. As a result, we can further optimize resource usage and improve code readability, navigation, and collaboration by customizing the specific needs of the code file.

基于每个文件启用行号允许开发人员自定义代码设置。因此,通过自定义代码文件的特定需求,我们可以进一步优化资源使用情况,并提高代码的可读性、导航性和协作性。

4. Using the Shortcut Key

4.使用快捷键

By enabling a line, we can jump directly to the specific line of code within the code, which makes navigation easier. Additionally, it assists in identifying code errors, reviewing code documentation, and finding duplicate code. Furthermore, we can enable this line in IntelliJ by using shortcuts. To illustrate, let’s look at the process step-by-step:

通过启用一行,我们可以直接跳转到代码中的特定代码行,从而使导航变得更容易。此外,它还有助于识别代码错误、查看代码文档和查找重复代码。此外,我们还可以通过使用快捷键在 IntelliJ 中启用该行。为了说明这一点,让我们一步步来看看这个过程:

  • Open the IntelliJ IDEA IDE
  • Press the Shift key twice
  • Type/Search line number
  • Enter to enable/disable the feature

In the below, we can see the final GUI to enable/disable the line number:

在下图中,我们可以看到启用/禁用行号的最终图形用户界面:

Shortcut

The above approach is beneficial and handy to enable/disable this feature. Furthermore, with a keyboard shortcut, we can easily toggle the absence of a line number in our code.

上述方法对于启用/禁用该功能非常有益和方便。此外,通过键盘快捷键,我们可以轻松切换代码中是否存在行号。

5. Conclusion

5.结论

In this article, we explored various ways to enable line numbers in IntelliJ IDEA. First, we looked at enabling line numbers for all the projects inside the IDE. After that, we also looked at performing the same for a specific file.

在本文中,我们探讨了在 IntelliJ IDEA 中启用行号的各种方法。首先,我们研究了在 IDE 中为所有项目启用行号的方法。之后,我们还研究了为特定文件启用行号的方法。

Finally, we enabled the line number using a keyboard shortcut.

最后,我们使用键盘快捷键启用行号。