How to display line numbers in eclipse| line number color

This post covers solving line numbers in the Eclipse code editor for the below things.

  • display line numbers in eclipse editor by default
  • Eclipse line number disappears after setting the “Show line settings” option
  • Changing the default line number color in the eclipse code editor

How to show or hide line numbers in Eclipse Editor

To show or hide line numbers in Eclipse, Please follow the below steps.

  • First, Go to Windows -> Preferences
  • It will open the preference window
  • Go to General - Editors - TextEditors
  • check “show line numbers”.

Please check the below screenshot as shown below.

eclipse show line numbers option on code editor

Eclipse editor displays the lines as seen below.

Eclipse enable disable line number

eclipse code editor show line number

It is another simple approach to adding lines to the eclipse code editor.

Here are the steps to do

  • Open any source code file. For example, Open the java class file
  • Class file is displayed in the Eclipse Code editor.
  • Next, Right-click on the left sidebar of a code editor
  • This will show the context popup window as shown below
  • Check the option - “Show Line Numbers” to enable code line numbers
Eclipse enable disable line number

eclipse short cut key to add line numbers in the code editor

Using shortcut keys in eclipse, We can enable/disable line numbers.

To display the line numbers. Click the Ctrl and F10 keys, - it opens a popup context window Select the keyboard N key - It selects Show Line Numbers options and displays the line numbers

To hide the line numbers.

Click the Ctrl and F10 keys, - it opens a popup context window Select the keyboard N key - It unchecks the Show Line Numbers options, and line numbers do not show.

Eclipse workspace settings to add line numbers by default

It is another option to configure workspace settings.

  • First, Go to the Project workspace folder
  • Select the .metadata folder
  • Open the org.eclipse.ui.editors.prefs located under below folder structure
B:\myworkspace\.metadata\.plugins\org.eclipse.core.runtime\.settings\org.eclipse.ui.editors.prefs
  • Add or update the below code to this file
lineNumberRuler=true

Once changes are done, Please restart the eclipse to take effect.

How to change the line number color in the eclipse console?

  • First, Go to Windows -> Preferences
  • It will open the preference window
  • Go to General -> Editors -> TextEditors
  • select the “Line Number foreground” option
  • Change the required color, Changed to Red color

Here is the screenshot

Change line number foreground color in eclipse

After changing the color, The line numbers color displayed as seen below

How to Change line number  color in eclipse