Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Editing in Eclipse - shortcut to copy a line?

 
Roger Yates
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a keyboard shortcut to duplicate a line of code?
E.g. Ctrl+D deletes current line.

I know I can: move to start of line, select to end of line, copy, paste
...but that's a bit long-winded.

There must be a combination to copy a whole line at once, just like that good old dos editor Brief, but I haven't found it yet. Anyone know if such a shortcut exists?
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18023
47
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ctrl+ALT+Down.

You can find this, and many other useful shortcuts under the Windows/Preference->Keys dialog. Or define your own!
 
Roger Yates
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim,

Thanks, but...
I have a tablet-pc and if I dare to use ctl-alt-down, my screen rotates upside-down.
and I couldn't see Windows/Preferences - Keys

however...
However, I've now disabled that little-used feature of my graphics driver in favour of the more useful copy line in Eclipse.

and you did lead me to find Windows/Preferences - General/Keys.

Thanks very much - an extremely useful page that one.

I'd found Ctl-Shift-L to get a list of key combinations and hadn't found anything, though now I see Ctl-Alt-down is there - I think the sheer number of shortcuts must have frazzled my brain.

Also Ctl-Alt-Up will duplicate lines.

So, as a summary for anyone interested:
  • Ctl-Alt-down: copies current line or selected lines to below
  • Ctl-Alt-up: copies current line or selected lines to above
  • Ctl-Shift-L: brings up a List of shortcut keys
  • Window/Preferences - General/Keys: allows you to modify the lot


  •  
    Roger Yates
    Ranch Hand
    Posts: 118
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    ... and for a shortcut to editing the shortcuts...

    When you've pressed Ctrl+Shift+L for the list of shortcuts, you can then press Ctrl+Shift+L again to get taken straight to the 'General/Keys' section of Windows/Preferences.

    i.e. Press Ctrl+Shift+L twice and you're there!

    I like Eclipse more and more.

    Now to find a shortcut to cut a whole line ready to be dropped somewhere else of my choosing...
     
    Ilja Preuss
    author
    Sheriff
    Posts: 14112
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Alt-up/down moves the current line up/down. I often use this in combination with ctrl-alt-up/down...
     
    Ilja Preuss
    author
    Sheriff
    Posts: 14112
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Forgot to mention: it also works with a selection of several lines.
     
    Roger Yates
    Ranch Hand
    Posts: 118
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks Ilja.

    So, as a summary for anyone else interested in copying/moving whole lines:

  • Ctrl+Alt+down: copies current line or selected lines to below
  • Ctrl+Alt+up: copies current line or selected lines to above
  • Alt+up: moves current line or selected lines to above
  • Alt+down: moves current line or selected lines to below
  • Ctrl+Shift+L: brings up a List of shortcut keys & pressing twice gets...
  • Window/Preferences - General/Keys: allows you to modify the lot


  • As an example, to copy a whole line somewhere else:
    1. Press Ctrl+Alt+up (or down)
    2. Press Alt+up (or down) as many times until you reach desired location.
     
    Paul Michael
    Ranch Hand
    Posts: 697
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I'm wondering why "Generate Getters and Setters" doesn't have a shortcut by default?

    Like Roger, I'm overwhelmed by the results from performing a "Ctl-Shift-L".

    Are you guys aware of comprehensive tutorials on eclipse shortcuts?

    That would really help a lot!

    Thanks,
    Paul
     
    Bill Zelan
    Ranch Hand
    Posts: 46
     
    Lars Vogel
    Ranch Hand
    Posts: 55
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I have listed my favorites shortcuts here: http://www.vogella.de/articles/EclipseShortcuts/article.html
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic