In a project in Intellij IDEA, You want to count the line numbers for a given java file.

We can count the line numbers in a java file using the statistics plugin or regular expression.

Intellij IDEA Count line of code

There are multiple ways we can count the number of lines of code in the Editor.

using statistics plugin:

  • Open IntelliJ IDEA editor
  • Select File > Settings, Opens Settings Popup Window
  • Select Plugin > type “Statistic” in search plugins.
  • Click on the Statistic install button
  • Next, click on Apply button and close the window
  • You will see the bottom panel with statistics being selected.

Intellij Editor count lines of code

  • you can use see below option
  • Refresh: It reloads and refreshes all the files in the project and calculates the statistics.
  • Refresh on selection: It selects selected files and output statistics.
  • Settings: Settings window

This plugin shows below the statistics of a given project or file.

  • File size
  • Lines count
  • min size
  • max size
  • Open Edit > Find > Find or use shortcut command Ctrl + F
  • It opens search box and select .* icon (regex - Alt +X)
  • In Search Box, Type below regular expression

\n: This includes the count of empty and non-empty lines and empty lines containing spaces. \n+: It gives only the count of non-empty lines of code.

  • It gives the line number count displayed in the beside search box