Photo from Chile

Three Eclipse (and CFBuilder) Shortcuts to Improve Your Life

OK folks, this is a big deal. I'm going to tell you about three keyboard shortcuts that you really need to incorporate into your routine. These are nothing new. Marc Esher blogged about these nearly a year ago, and there's a good chance that you're already using them, and if so, you know how amazing they are. But if you're not using them then you're really missing out.

If you're like me at first glance they won't seem like a big deal. You'll think, "How often do I need to do that?" But if you get yourself into the habit of using them, you won't believe how much more pleasant your time spent coding in Eclipse will be. Enough of the sales pitch, let's get on with it. The three shortcuts are:

  • Command+Option+Up/Down (Ctrl+Alt+Up/Down on a PC) - copy the selected line(s) above or below themselves
  • Option+Up/Down (Alt+Up/Down on a PC) - move the selected line(s) up or down
  • Command+D (Ctrl+D on a PC) - delete the selected line(s)

These commands blow cut/copy and paste out of the water. One of the best things about them is that you don't have to select an entire line to use them. Your cursor can be anywhere on the line(s) and it will work, so you don't have to bother hitting the Home key to move to the beginning of a line to copy, move or delete it. If this still doesn't seem like not a big deal to you, let's walk through a quick exercise. Take the following code and copy it into a file in Eclipse:

view plain print about
1<cfif something>
2    do something
3    that takes 2 lines of code
4<cfelseif somethingElse>
5    do something else
6    that takes 2 lines of code
7</cfif>
8
9<cfif anotherTest>
10    do something different again
11    that takes 2 lines of code
12<cfelse>
13    do something completely different
14    that takes 2 lines of code
15</cfif>

Let's say we want to add a similar cfelseif block into the second cfif block. Put your cursor anywhere on the existing cfelseif tag line and do shift+down x 2. You should now have part of the cfelseif line highlighted as well as all of the next line and part of the following line. Now do ctrl+alt+down. Your three lines of code have been duplicated immediately below the previously selected lines, and now they are selected. Now do alt+down x 5. Voila, you've copied your cfelseif block right where you needed it in very few keystrokes, and only had to lift your fingers from the keyboard once. Try that with copy and paste!

If you're still not with me on this one then I humbly suggest that you try doing it for a few days (or even just a few hours). Try to force yourself to use these shortcuts anytime that you need to copy, move or delete a line or block of code. I'm willing to bet you'll be hooked in very short order.

If you're wondering why I choose to blog about these now, I was inspired by a colleague. I only started using these shortcuts a few weeks ago and was kicking myself that I hadn't picked them up sooner. I was chatting with my friend and, somewhat , admitted that I had only started using them recently. "What do they do?" he asked. I was shocked that he too was not benefitting from their incredible usefulness, so I figured I should write this up to share this tidbit with everyone. Enjoy!

TweetBacks
Comments
I'm so happy.

Thanks!
# Posted By Aaron Greenlee | 1/22/10 2:10 PM
Good stuff Bob. You know, I've never used the ctrl-alt-down shortcut. So I gave it a shot after reading your post, and lo and behold, my whole screen flipped upside down. Good times...
# Posted By marc esher | 1/22/10 2:29 PM
Thanks for posting bob, very useful!

I use Command Left / Right quite a bit. It bring the cursor to the beginning or end of a line, if you add a shift it also selects the contents of the line.
# Posted By Pete Freitag | 1/22/10 2:34 PM
As a mouse happy Mac convert, baby steps like these, a few at a time, work for me. Keep 'em coming! Regards from the lower 48.
# Posted By Mitch Rose | 1/22/10 2:42 PM
I've been using the commands for only a few minutes
now and already my day is getting better. It's little
things like this that add up and can really make a
difference in your work. Thanks!
# Posted By Grant Copley | 1/22/10 2:57 PM
There is a fun plugin (www.mousefeed.com) that you can install that will nag you whenever you access a menu item with the mouse to use the shortcut instead.

The author hasn't updated the plugin in quite awhile but I have it running in Eclipse 3.5 w/CFEclipse with no issues.
# Posted By Jim Priest | 1/22/10 3:15 PM
I'm glad others are finding these shortcuts useful too.

@Jim: That is a very cool plugin. Thanks for sharing. I just installed it manually (it wouldn't install via Software Updates in CFBuilder) and it seems pretty cool.
# Posted By Bob Silverberg | 1/23/10 7:28 AM
here is my list of <a href="http://javarevisited.blogspot.com/2010/10/eclipse-...; useful eclipse shortcut </a> I would rather say very useful and practical eclipse shortcut :)

Thanks
Javin Paul
<a href="http://javarevisited.blogspot.com/2010/12/fix-prot... Protocol tutorial</a>
# Posted By Javin Paul | 1/8/11 8:06 AM