ChatGPT解决这个技术问题 Extra ChatGPT

Eclipse copy/paste entire line keyboard shortcut

Anyone know the keyboard shortcut to copy/paste a line into a new line in Eclipse, without having to highlight the entire line?

ctrl-alt-down turns my whole screen upside down (I'm on windows). Interestingly, that's what's specified in the windows->preferences.

Eclipse doesn't have this. IntelliJ does it very well. Ctrl-C will copy the whole line if nothing is highlighted. Also Ctrl-D duplicates a line as it is Ctrl-Alt-Down in eclipse.
Presumably flipping your screen upside down is not something you want to do often (unless you're a vampire/bat). Get rid of your graphics config and accept the best answer.
@fastcodejava Many people praised IntelliJ, but they still use eclipse. Is it because eclipse is the requirement of a team?
Change Key preferences in Eclipse, assign some other shortcut "ctrl+alt+shit+down arrow" to "copy lines" action.

a
andrewrjones

Ctrl-Alt-Down: copies current line or selected lines to below

Ctrl-Alt-Up:: copies current line or selected lines to above

Ctrl-Shift-L: brings up a List of shortcut keys

See Windows/Preference->General->Keys.


That makes my whole screen upside down (I'm on windows). Interestingly, that's specified in the windows/preference
If you are using Intel HD Graphics, it's quite possible that these shortcuts are binded by Intel graphics util. You can disable hotkeys from notification area util -> Graphic Options -> Hot Keys -> Disable. After that I could use those useful shortcuts.
try searching for it, you'd find this: stackoverflow.com/questions/591172/delete-a-line-in-eclipse
@Imray - Ctrl + D will delete the whole line.
In Ubuntu it does not work because CTRL+ALT+down and CTRL+ALT+up are already used (workspace switching). What you can do is to redefine 'copy lines' and 'duplicate lines' to other keys sequences. I have used CTRL+ALT+D for down and CTRL+ALT+U for up. It works perfectly.
K
KrishPrabakar

(Tested on Windows) [Per below comments, works as well in Ubuntu, IBM RTC 4 / RSA 9]

In Eclipse, press Ctrl+Shift+L two times in succession (or Ctrl + 3 > type: Keys > Enter). In 'type filter text' (search) text box, type Copy Lines Select the filtered row, right click the 'Binding' field, and do Select All Press Ctrl+Shift+V Give OK

From now on, for any line you want to duplicate, just press Ctrl+Shift+V.


i added Ctrl+D for copy paste current line successfully. thanks
I didn't use Ctrl + D as it is already a registered shortcut for deleting a line in Eclipse.
Works on IBM RTC 4 / RSA 9.
I'm using eclipse mars on windows but not getting any row while filtering.
Ctrl+Shift+V is now the shortcut that lets you paste in MyClass:123 and jump to line 123, and linkifies stack traces. Probably too useful to overwrite now.
c
clav

You have to turn off the graphics hot keys that flip the screen. If you're on Windows, you need to right click on the Windows desktop and select "Graphics Properties..." (or something similar depending on your version of Windows). This will bring up a screen where you can manage graphics and display options, look for a place where you can disable hot keys, sometimes it's hidden under something like "Options and Support". Turn off the CTRL + ALT + ↑ and CTRL + ALT + ↓ hotkeys (alternatively you can just disable all graphics hot keys if you're not using them).


It works like charm. I am using Windows 7. To disable all I did is to Right click on the Windows desktop and select "Graphics Properties" ->Options. Then selected "Off" at the left side on the resulting screen. This disabled all hotkey combination. I think there is no way to disable only some them, its all or none. Anyway I didn't need them.
Yay! I didn't even had to restart Eclipse, just disabled the Intel HD Graphics shortcuts and ctrl-alt-down just started working.
R
Renso Lohuis

If you want to copy a line to the clipboard you can also use the trick:

Ctrl-Alt-Down followed by Ctrl-X

The drawback is that the file where you copy the line from becomes dirty.


What do you mean by dirty?
I mean by dirty that the file is marked as changed by Eclipse, while the content is not really changed.
To copy a line to the clipboard, Shift+ Down, followed by Ctrl-C, might be a better idea.
That requires you to move your right hand from the mouse to keyboard and back. The whole point of a 'copy line' feature is to prevent that.
b
beam022

Ctrl-D would delete a line Ctrl-Z would undo deletion, with highlithing entire line Ctrl-X/C cut or copy entire line

The advantage over Ctrl-Alt-Down followed by Ctrl-X suggested by other users is that it doesn't make eclipse think that the file was changed in any way. It's also faster and causes no problems even if the user has rotating screen issue with Ctrl-Alt-Down/Up keyboard shorcut. So there's no need to remap shorcuts for this.

Another way to go would be hitting Alt-Shift-Up until the entire line gets selected. If you've gone too far, of course you can select less with Alt-Shift-Down.


One inconvenience is that it copies actually 2 lines, the original line plus line-break.
@user1278890 Sure, that might be considered both inconvenience or extra advantage :) Thanks for your feedback!
I
Imranmadbar

If Your Window pc, you may try this, it's also for STS:

Ctrl + win + Alt + Down :: Copy current line or selected line to below

Ctrl + win + Alt + Up :: Copy current line or selected line to above


l
larsch

I've written the linecopypaste plugin for Eclipse that mimics Visual Studio's copy/cut/paste behaviour. I've also found copycutcurrentline which appears to do the same.


C
Chris

On my Mac the default setting is is ALT+CMD+Down

You can change/view all key bindings by going Eclipse -> Preferences (shortcut CMD+,) and then General -> Keys


C
Community

Ctrl+Alt+Down Copies current line to below like notepad++ (Ctrl+D)

If your whole screen is 180° rotted then you should disable your hotkey settings.

Right Click -> Graphics Options -> Hot Keys -> Disable

https://i.stack.imgur.com/4cDwb.png

That it now you done try shortcut Ctrl+Alt+Down


H
Harsha

Try this in MAC.

ALT + COMMAND + DOWN

it works.


F
Fabich

If anyone using Mac computer the CTRL + ALT + DOWN keys doesn't work.

Try it with,

ALT + COMMAND + DOWN

It works.


N
Nicofisi

On Mac, I've tried the linecopypaste and it works great cmd+c -> Copy current (unselected) line, just like "yy" command in Vi/Vim cmd+v -> Paste it, like "p" command in Vi/Vim

Thank's Larsch for your work!

PD: Using Eclipse Luna 4.4.2 in Yosemite


A
Abdullah Khan

I have to change the assigned key, e.g.

Windows/Preference --> General --> Keys

Select "Duplicate Lines" under command Click on "Binding" Ctrl + Shift + D


H
Harvinder Singh

https://i.stack.imgur.com/mbjmJ.png


u
user1278890

Just another approach:

1) Alt+Up and Alt+Down (or Alt+Down and Alt+Up, order does not matter)
2) Ctrl+C

But of course vim's "yy" is the fastest :)


A
Abdullah Khan

Disabling the hot keys for the Intel Driver worked for me for Windows 7. However, for Windows 8, when I tried that, it prevented eclipse from getting the Ctrl-Alt-Down keystoke. I had to change the Intel driver key binding to Ctrl-Alt-F10 (or something else it will accept). Eclipse then gets the Ctrl-Alt-Down and copies the line.


Maybe its not available in all versions, but looking at the Intel HD Graphics Control Panel there's also an option to "Disable" all shortcuts underneath the "Mange Hot Keys" section. I just disabled it all... (irritating that they force you to specify a key binding for everything when "Manage Hot Keys" is enabled)
4
4b0

For mac, shift+alt+down_arrow works in netbeans' editor.


A
Abd Abughazaleh

It's working with me on , Eclipse + Spring tool suite .

ALT + COMMAND + DOWN


n
nanosoft

I am using Windows 7. To disable that all I did is to Right click on the Windows desktop and select "Graphics Properties" ->Options. Then selected "Off" at the left side on the resulting screen. This disabled all hotkey combination. I think there is no way to disable only some them, its all or none. Anyway I didn't need them. So now crtl+Alt+Up and Crtl+Alt+down works for me in Eclipse and my screen stays same :) I think similar option also exist in other versions of Windows. Have fun :)


E
Eugene

For personal usage, I add a vim plugin like Vrapper to Eclipse and just use yy to copy entire line.


F
Fabich

The Ctrl+Alt+Down / Ctrl+Alt+Up flips my screen so I overrode that in the Eclipse shortcuts via Window => Preferences => General => Keys. Search for "dupl" to find the Duplicate Lines command. I overrode the default and chose Ctrl+Shift+D. For me, that's easy to remember just like Ctrl+D to delete lines


F
Fabich

ctrl+alt+down/up/left/right takes precedence over eclipse settings as hot keys. As an alternative, I try different approach.

Step 1: Triple click the line you want to copy & press `Ctrl`-`C`(This will
select & copy that entire line along with the `new line`).
Step 2: Put your cursor at the starting of the line where you want to to paste
your copied line & press `Ctrl`-`V`.(This will paste that entire line & will
push previous existing line to the new line, which we wanted in the first place).

N
Nicofisi

The combination of Ctrl + Shift + Alt + Down worked for me on Linux.


N
Nicofisi

To copy text from the begining of line to the cursor position: ctrl + insert

It does the job and save a lot of time for me.


R
Ramnath

https://i.stack.imgur.com/Cqrrg.jpg

its best practice for beginner.