11

I am wondering if I have some code with line numbers embedded,

 1 int a;     
 2 MyC b;    
 3 YourC c;

etc., and then I copy them and try to paste them in Eclipse, how to get rid of these line numbers to make the source code valid? Is there any convenient way, or a short-cut key?

Thank you.

Roman Byshko
  • 8,591
  • 7
  • 35
  • 57
Qiang Li
  • 10,593
  • 21
  • 77
  • 148

5 Answers5

13

Simply use the Alt+Shift+A (Eclipse 3.5 M5 and above) shortcut to toggle block selection mode. Then select the column with line numbers and delete it!

To make it easier you could setup a macro, but for that you need additional plug-in. I'm not aware of how to do it even easier.

Roman Byshko
  • 8,591
  • 7
  • 35
  • 57
  • It is good to be able to do this. But still not very automatic. Do you or others know any "more" convenient way of doing this? Sorry for being so "picky". – Qiang Li Nov 29 '11 at 23:03
  • @QiangLi See my updated answer. Consider accepting it if you were satisfied. – Roman Byshko Nov 30 '11 at 00:19
  • For anyone reading who is developing for Android and using the ADT with Eclipse, you won't be able to use this shortcut initially because ADT hijacks this key combination. You can still reach it from the *search commands (Ctrl + 3 on Windows)* though. Or you can remap it to something else like they did in [**this answer here**.](http://stackoverflow.com/a/7862385/708906) – Tony Chan Oct 20 '14 at 12:29
10

Try this link. This is a dynamic online tool, where it is very easy to just copy paste code and get code without line numbers:

http://remove-line-numbers.ruurtjan.com/

JonathanDavidArndt
  • 2,518
  • 13
  • 37
  • 49
0

I removed line numbers by find and replace with regular expression option. Replacing regular expression \d+\s\s with empty string where \d+ means any combination of numbers and \s is actually a space (This is to avoid any numbers present in the code).

RootCode
  • 569
  • 7
  • 12
0

Best way is use SED command. Here you can specify as many as digit you want to replace. in below example open copied code in VI editor and assuming its containing upto 1000 lines. :%s/^[0-9][0-9|10-99|100-999]//g if you want to use more lines then put one more or condition.

0

You could use some script to do the work. For instance, using sed

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547
  • How is sed integrated into eclipse, though? Are you assuming the OP wants to save to a file first? What platforms is this supported on? What do you recommend for WinXP? – sehe Nov 29 '11 at 22:52
  • 2
    @sehe If unix tool, then `cut` is just the right weapon. sed is imho overkill. – Roman Byshko Nov 29 '11 at 22:55
  • @RomanB. True, but _if tagged [tag:eclipse]_, see [here](http://stackoverflow.com/a/8318880/85371) though! – sehe Nov 29 '11 at 22:57
  • @RomanB.: colour me silly. I wasn't joking, I hadn't noticed! – sehe Nov 29 '11 at 22:59