This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes IDEs, Version Control and other tools and the fly likes Editing in Eclipse - shortcut to copy a line? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "Editing in Eclipse - shortcut to copy a line?" Watch "Editing in Eclipse - shortcut to copy a line?" New topic
Author

Editing in Eclipse - shortcut to copy a line?

Roger Yates
Ranch Hand

Joined: Aug 31, 2004
Posts: 118
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?


Cheers,<br />Roger<br />SCJP 1.2, 1.4, SCBCD 1.3, SCWCD 1.4
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16022
    
  20

Ctrl+ALT+Down.

You can find this, and many other useful shortcuts under the Windows/Preference->Keys dialog. Or define your own!


Customer surveys are for companies who didn't pay proper attention to begin with.
Roger Yates
Ranch Hand

Joined: Aug 31, 2004
Posts: 118
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

    Joined: Aug 31, 2004
    Posts: 118
    ... 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

    Joined: Jul 11, 2001
    Posts: 14112
    Alt-up/down moves the current line up/down. I often use this in combination with ctrl-alt-up/down...


    The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
    Ilja Preuss
    author
    Sheriff

    Joined: Jul 11, 2001
    Posts: 14112
    Forgot to mention: it also works with a selection of several lines.
    Roger Yates
    Ranch Hand

    Joined: Aug 31, 2004
    Posts: 118
    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

    Joined: Jul 02, 2001
    Posts: 697
    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


    SCJP 1.2 (89%), SCWCD 1.3 (94%), IBM 486 (90%), SCJA Beta (96%), SCEA (91% / 77%), SCEA 5 P1 (77%), SCBCD 5 (85%)
    Bill Zelan
    Ranch Hand

    Joined: Jan 09, 2009
    Posts: 46
    http://code.google.com/p/copycutcurrentline/
    Lars Vogel
    Ranch Hand

    Joined: Oct 10, 2007
    Posts: 55
    I have listed my favorites shortcuts here: http://www.vogella.de/articles/EclipseShortcuts/article.html


    Tutorials about Java, Eclipse and Webprogramming http://www.vogella.de
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Editing in Eclipse - shortcut to copy a line?