As my coworkers know, I’m a keyboard shortcut junkie. It’s a problem (and I need help), but I’d rather give you a taste of what I’ve been smoking and drag you down with me :).
Why only 3? Because people don’t learn a couple of pages of keystroke combinations at a time. But with only the 3 of the best keystrokes, there’s a good chance I’ll get you hooked and you’ll seek out some more.
- Incremental Search Through Command History -
Most people know that pressing the up arrow at a prompt will go to the previous command, and subsequent up arrows will move backwards in history.
That works fine for commands that you just typed. What if you had checked out the grails trunk a week ago and wanted to do it again, but couldn’t remember the exact repository name. Just type ctrl-R and then a part of the command that you can remember, such as
- Delete Last Word -
There are a number of great movement and deletion commands (almost all of them originating from emacs keybindings). But
- Insert Last Argument of Previous Command -
How many times have you wanted to do 2 things with a file or directory in succession? It happens all the time to me and this is my favorite command that I’ve never seen anyone else use.
For example, if I want to do a quick update of one of my domain classes from subversion:
svn co. As you type it will search backwards through your command history for a command that matches. When your comamnd appears, just hit enter to execute.
svn co http://svn.codehaus.org/grails/trunk/grails/ grails bck-i-search: svn co_If there were multiple commands that match the pattern that you typed, either type more of the command to get more specific, or hit
ctrl+Ragain to find the next most recent command that matches the pattern.
ctrl+Wis the one I use more often than any other. It deletes the previous word On the mac, one other benefit of knowing these keybindings is that they work in just about every cocoa based application as well as a few other apps. For example, in Firefox, ctrl-W will work on the location bar to make it easy to delete parts of an URL. Once these commands become part of your muscle memory, you’ll find yourself using them all over the place.
svn up grails-app/domain/Author.groovyand then edit it in TextMate, all I have to do is type
option+.and it autocompletes to:
mate grails-app/domain/Author.groovyThere is a word designator shortcut, ”
!$”, that also means “last parameter of previous command”, but with ctrl-. you actually get to inspect and edit the parameter easily. Also, on OSX,
escis the default “meta” key, but you can (and should) go into the terminal preferences and check the “Use option as meta key” checkbox on the Keyboard tab.
If you’re interested in learning more about terminal history commands, I highly recommend The Definitive Guide to Bash Command Line History.