749

How can I show line numbers by default in Eclipse?

hichris123
  • 9,735
  • 15
  • 51
  • 66
  • 1
    What do you mean, "by default"? For each new workspace? For each new install of eclipse? I'm confused. – Ryan Emerle Mar 12 '09 at 23:32
  • 43
    @Uri: Ehm, so that when you get an error message thrown at you by the compiler you can quickly find the line by scanning the document with your eyes. – X-Istence Mar 13 '09 at 05:35
  • 9
    @X-lstence ctrl-l will bring up a pop up box where you can enter a line number to jump to – jklp Jul 15 '09 at 03:51
  • 12
    Still I find it much faster when using a tool like lint to scroll to each line when there are multiple errors and having a way to show line numbers is invaluable. Also when taking screenshots it can be nice to see the original line numbers for discussion purposes. – Tod Apr 11 '12 at 18:56
  • 4
    Big News! (reported by Lars VOGEL): starting 4.4M4, line numbers are activated *by default*! See [my (edited) answer below](http://stackoverflow.com/a/641540/6309) – VonC Dec 11 '13 at 15:05

16 Answers16

1105

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":

Arsen Khachaturyan
  • 6,472
  • 4
  • 32
  • 36
fbernier
  • 12,208
  • 2
  • 22
  • 30
  • 83
    Thank you! I can't believe three different people tried telling the OP that they didn't want line numbers rather than just answering the question. Shame on the developers of Eclipse for hiding it in such an obscure location, though... it shouldn't have to take a half dozen clicks to turn such a simple thing on. – ArtOfWarfare Jul 27 '12 at 12:58
  • 9
    Thanks! I'm using the Juno release and eventually found it under eclipse -> preference -> general -> editors -> text editors -> show line numbers. – Doug English Jul 29 '12 at 03:57
  • 8
    @ArtOfWarfare That is what happens when you let developers design the UI. – Blaise Swanwick Dec 21 '12 at 16:33
  • 44
    Interesting that I didn't notice the other very good solution to this answer... right click in the gutter and choose "Show Line Numbers". – ArtOfWarfare Dec 21 '12 at 17:38
  • In Eclipse for Mac, it's not in Window->Preferences but in Eclipse->Preferences – Marcel Marino Dec 09 '13 at 19:57
  • 2
    @ArtOfWarfare Shame on the developers of Eclipse for creating Eclipse. – Josh Jan 10 '14 at 17:26
  • 1
    Wow, that comment is easily the most up voted thing I've ever done on StackOverflow. Too bad you don't get rep for comment up votes. I've never even received notifications for it, until Soylent Green just commented on it. And yes, shame on them for making such a lousy IDE. – ArtOfWarfare Jan 10 '14 at 18:44
  • Personally I really quite find this very annoying. Please correct me if I am wrong but I believe line numbers are very common if not, important part of any IDE and on Eclipse it is turned off by default. Thanks for the answers. Cheers! – Neon Warge Jan 20 '15 at 07:55
  • Why would that not be automatic? – Kolob Canyon Mar 09 '16 at 22:29
  • I can't quite believe that the option is hidden five levels down! "On display? I eventually had to go down to the cellar to find them." "That's the display department." "With a torch." "Ah, well the lights had probably gone." "So had the stairs." "But look, you found the notice didn't you?" "Yes, yes I did. It was on display in the bottom of a locked filing cabinet stuck in a disused lavatory with a sign on the door saying *Beware of the Leopard*." – CJ Dennis Dec 24 '16 at 03:43
  • @CJDennis Or you can just type "line" or even "line number" in the search bar of the preferences. That's something they did do right. Besides that it *is* in a logical location. – Maarten Bodewes Jul 23 '17 at 08:30
483

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

Tod
  • 7,806
  • 5
  • 46
  • 85
voidstate
  • 7,658
  • 4
  • 36
  • 50
94

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:

lineNumberRuler=true

(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 "Mkyong.com"

Community
  • 1
  • 1
VonC
  • 1,042,979
  • 435
  • 3,649
  • 4,283
  • On the current Eclipse Mars version (4.5.1), line numbers are not enabled by default (annoyingly). – AStopher Nov 14 '15 at 12:34
  • How can I set left indent spacing, to add some space between line number and the first character of each line? – Ωmega Oct 04 '19 at 13:05
  • @Ωmega 10 years later, I don't know. that would be space or padding between the gutter and the code editor. – VonC Oct 04 '19 at 13:12
30

As simple as that. Ctrl+F10, then N, to Show or hide line numbers.

Reference : http://www.shortcutworld.com/en/win/Eclipse.html

Elrond_EGLDer
  • 47,430
  • 25
  • 189
  • 180
shaby
  • 1,057
  • 1
  • 13
  • 17
  • One need to have focus in the Editor for that shortcut to work, but that is pretty obvious if one reads the section title in the referred article. :-) – Björn Larsson Sep 27 '18 at 10:24
25

Slight variation on Mac OSX:
Eclipse → Preferences → General → Editors → Text Editors → Show line numbers

AlvaroCachoperro
  • 661
  • 6
  • 10
crsierra
  • 1,035
  • 10
  • 6
20

Windows → Preferences → General → Text Editors → Show numberlines

HANU
  • 505
  • 1
  • 6
  • 13
19

in this file

[workspace].metadata.plugins\org.eclipse.core.runtime.settings\org.eclipse.ui.editors.prefs

make sure the parameter

lineNumberColor=0,0,0

is NOT 255,255, 255, which is white

Antonio Leite
  • 407
  • 3
  • 7
  • Does that mean you can have different colors of line numbers? Interesting. I will try that sometime soon. – Greeso Jan 11 '13 at 11:32
18

Go to Windows → Preferences → General → Text Editors → Show numberlines. Click OK, then Apply changes. Then it will show the line count automatically.

ЯegDwight
  • 23,615
  • 10
  • 43
  • 51
bhejaFry
  • 697
  • 1
  • 7
  • 12
  • Maybe you mean to press Apply and then OK, although pressing OK suffices. Still I don't think this answer offers something new compared to top answer. Isn't it a kind of answer that should be merged? – kon psych Mar 28 '13 at 14:15
  • The steps are given to help some folks, algorithm explained is for easy understanding. Hope it helps you! – bhejaFry May 31 '13 at 07:54
9

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

Arul Pandian
  • 1,475
  • 14
  • 20
7

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.

DevC
  • 6,005
  • 8
  • 34
  • 56
7

Open Eclipse

goto -> Windows -> Preferences -> Editor -> Text Editors -> Show Line No

Tick the Show Line No checkbox

Ujjwal Roy
  • 320
  • 3
  • 8
4

click on window tab and click on preferences

click on window tab

do this and check show line number

check show line number

Adiii
  • 35,809
  • 6
  • 84
  • 87
3

the eclipse changes the perferences's position

to eclipse -> perferences

3

On a Mac do this:

cmd + , or ADT -> Preferences 

Expand General -> Editors ->Text Editors

Check box: Show line numbers

enter image description here

Mike Zriel
  • 1,141
  • 1
  • 12
  • 26
2

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...

wizurd
  • 3,131
  • 3
  • 29
  • 47
1

this will be the appropriate solution for asked question:

String lineNumbers = AbstractDecoratedTextEditorPreferenceConstants.EDITOR_LINE_NUMBER_RULER; EditorsUI.getPreferenceStore().setValue(lineNumbers, true);

RTA
  • 1,171
  • 2
  • 13
  • 31