Monday, August 9, 2010

Things I Love About IntelliJ IDEA: Fast Line Copy & Cut

One of the most common things I do when coding is to copy or cut a single line. The JetBrains guys, having realised this, have made it really easy to do: If you have nothing selected in IntelliJ IDEA and you press Ctrl-C or Ctrl-X, it will copy or cut the current line (respectively, not randomly!). In Eclipse, to copy or cut a line you first have to make the sequence of keystrokes to select the line (Home, Home, Shift-Down) and then copy it with Ctrl-C or cut it with Ctrl-X.

It may not seem like a big difference, but once you've enjoyed the convenience of not having to select a line before copying it, moving back to the select-then-execute method is like moving from a ballpoint pen back to a quill & ink. The difference is simple, but the cumulative effect is lots of time saved. (Look after the pennies.)

6 comments:

  1. Another shortcut I use all the time and dearly miss in every other editor is Ctrl-D, which simply duplicates the current line in one go.
    Along with quickly moving lines up and down through the current block (Shift-Ctrl-Up and Shift-Ctrl-Down) it is one of the many things that really make IDEA shine...

    ReplyDelete
  2. Another that a surprising number of people don't know about is Ctrl-D. With nothing selected, the current line will be duplicated. Surprisingly useful.

    ReplyDelete
  3. Ctrl-D (duplicate) is definitely a winner. It can also duplicate a block, of course. Eclipse has the same functionality mapped to Ctrl-Alt-Down, and has a "duplicate upwards" function mapped to Ctrl-Alt-Up. Confusingly, Ctrl-D in Eclipse deletes a line, so when I forget which IDE I'm in I sometimes expect to duplicate a line but it disappears instead.

    ReplyDelete
  4. In Eclipse there's the Ctrl+Alt+Up/Down shortcut which duplicates the current line. Then you can move the line up or down with Alt+Up/Down (let go of Ctrl).

    Very useful, but not many people know about it.

    ReplyDelete
  5. The big plus of the CTRL-D is that is does not overwrite your paste buffer. So you can copy a small piece from somewhere, then copy a line with CTRL-D and when you hit CTRL-V to paste, it will contain the small piece still. I cannot tell you how many times I already used that!

    ReplyDelete
  6. Being able to cut/paste and duplicate a line is pretty much expected if you are used to using VI. IntelliJ has a great VI plugin (IDEAVim) and it supports VI's "yy" and p for the exact same functionality as you describe. You never have to take your fingers off of home row.

    ReplyDelete