Customizing Cut line in eclipse with Ctrl-X
Asked Answered
A

6

21

Is it possible to configure Eclipse to cut lines with Ctrl+X? Is it more intuitive and leave Ctrl+D to duplicate lines? I am trying IntelliJ now and keep typing Ctrl+D to delete lines which duplicates.

EDIT : Wow, already five responses. I want Ctrl+X to cut the whole line if nothing is selected, otherwise do a regular cut. Same thing with Ctrl+C. It is a nice feature in IntelliJ.

Aerostation answered 1/1, 2011 at 18:25 Comment(6)
Except that Ctrl-X requires you to select what you're cutting. I'm guessing the OP wants Ctrl-X to delete the line containing the cursor, regardless of whether anything is selected or not.Mariquilla
He wants a totally different operation from what Ctrl-X currently does. Does it matter whether it's intuitive? It's clearly something Eclipse can do, since Ctrl-X is rebound for the Emacs bindings. I don't use Eclipse enough to have the answer off the top of my head, but if it's his copy of Eclipse, and that's how he wants it to behave, why does the discussion of whether it's intuitive or not even matter?Mariquilla
Fair enough. As long as he gets his answer. ;-)Mariquilla
But Eclipse already has wonderful hotkey for duplicating lines! @fastcodejava, why not stick to Eclipse conventions? See @Krof Drakula's answer below.Ambidextrous
@Ambidextrous - It is not wonderful, Ctrl-D is more usual way to do it.Aerostation
Scintilla has Ctrl+D IIRC.. but I found myself trying to remap it to Eclipse-style whenever I worked with any Scintilla-based IDE. It's just more natural to be able to transpose/duplicate in both directions.Ambidextrous
K
18

Every time I istall Eclipse I forget it doesn't have this functionality by default and have to search to fix it.

This plugin works for me and does exactly (and only) what the original poster asks for

http://code.google.com/p/copycutcurrentline/

Knoxville answered 9/8, 2012 at 8:4 Comment(5)
In Juno, it works perfectly, now eclipse the perfect IDE, thanks so much!Audiophile
It works in flash builder. But interestingly I had to restart it more timesSyblesybley
You'll have to build it from source now, Google Code is not hosting the downloads.Substage
You don't have to build it from source. The download links on the start page of the projects just dont work anymore. But you can get it from the download page (code.google.com/archive/p/copycutcurrentline/downloads). There the download link is working. Works nicely with Eclipse Neon.3!Interpretative
Still works with my Eclipse 4.9.0. Downloaded the .jar and put it to my dropin folder at /usr/lib/eclipse/dropins/.Anetta
R
11
  1. Click Window -> Preferences
  2. Expand General -> Keys
  3. Set filter text to: cut
  4. Select Cut Line
  5. Set Binding to: Ctrl+x
  6. Select Cut
  7. Set Binding to empty (by pressing Backspapce).

You can also swap the Binding for Delete Line and Duplicate Line commands within the Preferences dialog.

Cut line

Rieger answered 1/1, 2011 at 18:29 Comment(1)
unfortunately, this does perform the action even if something is selected. The wish is to cut the whole line only if "nothing is selected".Rizzi
C
4

Yes, use the Preferences dialog to configure the keyboard shortcuts. But I find the defaults to be more useful:

  • Alt+Down duplicates line below current line (Up duplicates above)
  • Ctrl+Alt+Down swaps the current line with the line below it (Up swaps with line above), essentially moving the current line up or down
Clubhouse answered 1/1, 2011 at 18:29 Comment(1)
+1! The Eclipse-ish way of duplicating/transposing lines is just so much more intuitive than standard Scintilla's ctrl+T / ctrl+D.Ambidextrous
H
2

I've searched for the same functionality - moving the line (Alt-arrow) or duplicating (Ctrl-Alt-arrow) is not the same - not when you want to get the line into completely different file, for instance.

There is an issue on Eclipse's bugzilla for this - since 2002.

IntelliJ IDEA has Ctrl+X/C when nothing is selected (and hardly was first editor to do it that way) and it just works really nicely. You can somehow imitate this behavior for copy - duplicate the line and cut it (Ctrl-Alt-arrow down, then Ctrl+x).

Hi answered 22/3, 2011 at 6:36 Comment(1)
...since 2002! I just don't understand why core editing features of this platform are not a priority for the devs. Especially for such a simple feature that improves editing without any doubt. Think about all the useless clicks you did to compensate!Aleron
A
2

I want Ctrl+X to cut the whole line if nothing is selected, otherwise do a regular cut. Same thing with Ctrl+C. It is a nice feature in IntelliJ.

I created an Eclipse Plugin for this.

Eclipse Marketplace: https://marketplace.eclipse.org/content/lineshortcuts

GitHub: https://github.com/achimmihca/EclipseLineShortcuts

Aleron answered 4/11, 2019 at 16:0 Comment(2)
I must note that copying the line with this plugin is not perfect. I did not find a proper "copy line" action in Eclipse, only "duplicate line". So as work-around I do "select line" followed by "copy line". Of course, you lose your caret position with that. Anyway, "cut line" works as expected using the default action of Eclipse.Aleron
Thank you for sharing! Very helpful compatibility plugin for people, who are used to also occasionally work in other contemporary editors.Styracaceous
M
0

You can already delete lines with CTRL+X! (In fact you cut them, but however they are not there anymore)

Marquand answered 1/1, 2011 at 18:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.