this will be the appropriate solution for asked question:

string linenumbers = abstractdecoratedtexteditorpreferenceconstants.editor_line_number_ruler; editorsui.getpreferencestore().setvalue(linenumbers, true);


eclipse has a search feature in the top left box of the preferences. type in 'line numbers' in that search box, and presto...

in case you're tired of googling each time you forget...


the eclipse changes the perferences's position

to eclipse -> perferences


on a mac do this:

cmd + , or adt -> preferences 

expand general -> editors ->text editors

check box: show line numbers

enter image description here


click on window tab and click on preferences

click on window tab

do this and check show line number

check show line number


the top answer is good but you can also bind it to a key ( shorcut ) to toggle it..

window > preferences > keys then enter "line numbers" in filter and bind it to a key.

i use ctrl + s + l.


open eclipse

goto -> windows -> preferences -> editor -> text editors -> show line no

tick the show line no checkbox


one of the easy way is using shortcuts like : ctrl+f10, then press n "it show line number and hide line numbers.


go to windows → preferences → general → text editors → show numberlines. click ok, then apply changes. then it will show the line count automatically.


in this file


make sure the parameter


is not 255,255, 255, which is white


windows → preferences → general → text editors → show numberlines


slight variation on mac osx:
eclipse → preferences → general → editors → text editors → show line numbers


as simple as that. ctrl+f10, then n, to show or hide line numbers.

reference :


update november 2015:

in eclipse mars 4.5.1, line numbers are (annoyingly) turned off by default again. follow the below instructions to enable it.

update december 2013:

lars vogel just published on his blog:

line numbers are default in eclipse sdk luna (4.4) as of today

(december 10, 2013)

we conducted a user survey if users want to have line numbers activated in text editors in the eclipse ide by default.
the response was very clear:

yes : 80.07% (1852 responses)
no  : 19.93% (461 responses)
total  : 2313
skipped:   15

with bug 421313, review - line number should be activated by default, we enabled it for the eclipse sdk build, i assume other eclipse packages will follow.

update august 2014

line number default length is now 120 (instead of 80) for eclipse mars 4.5m1.
see "how to customize eclipse's text editor code formating".

original answer (march 2009)

to really have it by default, you can write a script which ensure, before launching eclipse, that:
[workspace]\.metadata\.plugins\org.eclipse.core.runtime\.settings\org.eclipse.ui.editors.prefs does contain:


(with [workspace] being the root directory of your eclipse workspace)
then eclipse will be opened with "line numbers shown 'by default' "

otherwise, you can also type 'ctrl+1' and then "line", which will give you access to the command "show line numbers"
(that will switch to option "show line numbers" in the text editors part of the option.

or you can just type "numb" in windows preferences to access to the text editor part:

show line number

picture from "how to display line numbers in eclipse" of blog ""


if this doesn't work it may be overridden by your current settings. you can right-click in the bar to the left of the code where line numbers would normally appear and turn them on with the context menu.

screen showing this context menu


window → preferences → general → editors → text editors → show line numbers.

edit: i wrote this long ago but as @artofwarfar and @voidstate mentioned you can now simply:

right click the gutter and select "show line numbers":

Related Query

More Query from same tag