Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Duplicate whole method via keyboard shortcut?

I often use Ctrl + D to copy one line of the code.

Is there a keyboard shortcut in IDEA where I can put a caret on the method name and pressing the shortcut combination duplicate the whole method? Ctrl + D does not help in such case.

like image 921
sandalone Avatar asked Aug 08 '13 15:08

sandalone


2 Answers

Until IDEA does not get a built-in feature like this, you can use this approach (it's pretty quick):

  1. Put caret on the method name line or anywhere inside the method itself
  2. Ctrl + Minus
  3. Ctrl + D
  4. Ctrl + Plus

Or make a Macro like @CrazyCoder suggested.

like image 99
sandalone Avatar answered Oct 18 '22 15:10

sandalone


You can use first Ctrl + W to select method. Then Ctrl + D to duplicate selected lines.

like image 27
Viktor Kuchyn Avatar answered Oct 18 '22 15:10

Viktor Kuchyn