Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

intellij - way to do the eclipse CTRL+ALT+UP duplicate lines upwards and end up with carets in duplicated field?

I want to duplicate just like the standard CTRL+D hotkey in intellij, but in the eclipse version was a way to end up in the duplicated lines with the caret. E.g. the original is at the bottom and you are set to edit the duplicated lines at the top with the caret.

E.g. CTRL+D does this

| <-- caret


originaltext|   (hit CTRL+D) you end up with

duplicatedoriginaltext
originaltext|

but what i want
duplicatedoriginaltext|
originaltext

is there a way to do this in intellij? and obviously this has to work with several lines as well.

like image 862
Toskan Avatar asked Nov 28 '13 04:11

Toskan


3 Answers

IntelliJ has a feature similar to eclipse's CTRL+ALT+DOWN feature. It's not set by default, and you can set it in the Keymap under the Editor Actions grouping. Its called Duplicate Lines.

IntelliJ Keymap

like image 197
spierce7 Avatar answered Oct 21 '22 23:10

spierce7


A bit late to the party but I created a plugin to do just that:

https://plugins.jetbrains.com/plugin/10008-duplicate-lines

Supports single lines, multiple selected lines, multiple carets and block selection.

Default shortcuts are "Shift + Ctrl + Alt + Up/Down" and "Shift + Command + Option + Up/Down" for macOS.

And is compatible with IntelliJ IDEA, PhpStorm, WebStorm, PyCharm, RubyMine, AppCode, CLion, Gogland, DataGrip, Rider, MPS and Android Studio.

Source code: https://github.com/xusoo/duplicate-lines-intellij-plugin

like image 10
xuso Avatar answered Oct 21 '22 23:10

xuso


I can tell you how I solved this problem. I use Autohotkey and just mapped Ctrl+Alt+Up to duplicate line, then move the line up.

like image 2
nsinkov Avatar answered Oct 21 '22 23:10

nsinkov