Nick Rutherford

I can't emphasise enough how useful it is to learn keyboard shortcuts, at very least for cursor navigation coupled with shift selection, if you are doing a lot of typing. My driving reason for using them is RSI evasion, but they are also just pretty damn cool to use.

I'm a recent TextMate convert, and as I pick up tricks I'll share them here. This isn't going to be a complete reference, rather it'll be things I find useful.

Why learn the combos?

If you're asking that I guess you've not played Tekken against a friend who learned all the moves in practice mode. You'd have to rephrase the question then.

I can't emphasise enough how useful it is to learn keyboard shortcuts, at very least for cursor navigation coupled with shift selection, if you are doing a lot of typing. My driving reason for using them is RSI evasion, but they are also just pretty damn cool to use.

They do save you time, and are actually easy to remember because once you pick them up you will use them all the time - this means they'll quickly progress from your short term to medium term memory, and as you aren't likely to stop using them they'll go long term and you'll be stuck with them for life!

I'm a recent TextMate convert, and as I pick up tricks I'll share them here. This isn't going to be a complete reference, rather it'll be things I find useful.

Why TextMate?

Well, the short answer is Ian and Ray use it. I've not had a Mac long enough to agree or know better, so it was an easy choice!

The only thing I can fault it on so far is folders in the sidebar don't act like finder folders, so I can't send them to Launchbar to pass on to another application - this is pretty minor.

I can't really compare TextMate with other *nix editors as I tend to shy away from emacs and vi and end up using nano or cat for typing. They had too steep a learning curve for the time I had; I needed something that worked out of the box, which TextMate does, and at that time gEdit, jEdit (lovely split window editing, cross platform in Java) and nano did. Cat doesn't even have a box, it's more like eating your steak blue.

Sources

My main sources of information at present are the manual and TextMate - Power Editing For the Mac. Our very own Ian White and Ray Drainville gave me a few pointers too!

Viewing and Navigating a file

I'll start light, with something that won't break any files you're opening (don't use it to babysit your kids, watch the dog, etc etc).

Folding your code

F1 fold/expand current section

Some language grammars will (or should) support code folding, e.g. Ruby, C, PHP. You'll see arrows in the gutter (by your line numbers, on the left) showing where the limits of a section are, and whether it's current folded or not.

To fold nested sections hold opt while click folding (doesn't work with F1).

You may also find the View -> Toggle Foldings at Level commands and shortcuts useful.

Closing the current file tab

cmd w This one may seem obvious, but it could cause some confusion with closing the window or just 1 tab.

Bookmarks

cmd F2 set/delete bookmark at current line F2 go to next bookmark

Common cocoa cursor navigation

  • cmd up = start of file
  • cmd down = end of file
  • cmd left = beginning of line
  • cmd right = end of line
  • cmd backspace = delete to start of line
  • cmd fn backspace = forward delete, to end of line (like ctrl k below)
  • opt left/right = navigate by word start/end (notice the Text Editing option Word Characters which allows you to add things you consider to count as part of a word. e.g. _ is often part of a word when you are dealing with snake_case_function_names)

readline shortcuts

*nix, emacs, bash terminal, also in Cocoa apparently. These are very handy to know, as you'll be able to use them in other unix distributions, e.g. Linux, if you find the need.

  • ctrl a = go to start of line
  • ctrl k = kill to end of line (delete everything from your cursor to the line end)

use the above 2 in succession to blank a terminal line

  • ctrl e = go to end of line
  • option b = back one word
  • option f = forward one word

Terminal option meta key and # issues

An unfortunate gotcha is that when you set the option key to act as the meta key for the Terminal you lose your ability to enter #s on Macbooks; I've not chased this yet but if I find a work around I'll post it here. I seem to be moving towards editing with textmate rather than in the terminal for messages etc (# is important for github/lighthouse commit message integration).

Line wrapping quirk

Try using ctrl a and cmd left on a line which TextMate has wrapped across two or more lines, you'll see that one goes to the actual start of the line, and one goes to the start of the line you can see on screen.

Go To File

cmd t

This is nothing like your usual file open dialogue, it's more like Spotlight and you should try it out. If you know the filename you want it'll take you straight there, no path navigation.

It also adapts to your usage over time, and you can do things like assign abbreviations just by using them then selecting what you want the first time or two to train it.

Go To Symbol

shift cmd t

This means 'go to function', 'go to section', 'go to chapter', and so on depending on what language or mark-up you are editing.

If your language's grammar is supported by TextMate so that it has 'symbols' you can use both the menu to the bottom right of the edit window, and this dialogue to go to where you want to be. It works just like the go to file menu.

Viewing and Navigating a file

I'll start light, with something that won't break any files you're opening (don't use it to babysit your kids, watch the dog, etc etc).

Folding your code

F1 fold/expand current section

Some language grammars will (or should) support code folding, e.g. Ruby, C, PHP. You'll see arrows in the gutter (by your line numbers, on the left) showing where the limits of a section are, and whether it's current folded or not.

To fold nested sections hold opt while clicking a fold marker in the gutter (doesn't work with F1).

You may also find the View -> Toggle Foldings at Level commands and shortcuts useful.

Closing the current file tab

cmd w This one may seem obvious, but it could cause some confusion about whether it closes a tab or the TextMate window.

Bookmarks

cmd F2 set/delete bookmark at current line F2 go to next bookmark

Common cocoa cursor navigation

  • cmd up = start of file
  • cmd down = end of file
  • cmd left = beginning of line
  • cmd right = end of line
  • cmd backspace = delete to start of line
  • cmd fn backspace = forward delete, to end of line (like ctrl k below)
  • opt left/right = navigate by word start/end (notice the Text Editing option Word Characters which allows you to add things you consider to count as part of a word. e.g. _ is often part of a word when you are dealing with snake_case_function_names)

readline shortcuts

*nix, emacs, bash terminal, also in Cocoa apparently. These are very handy to know, as you'll be able to use them in other unix distributions, e.g. Linux, if you find the need.

  • ctrl a = go to start of line
  • ctrl k = kill to end of line (delete everything from your cursor to the line end)

use the above 2 in succession to blank a terminal line

  • ctrl e = go to end of line
  • option b = back one word
  • option f = forward one word

Terminal option meta key and # issues

An unfortunate gotcha is that when you set the option key to act as the meta key for the Terminal you lose your ability to enter #s on Macbooks; I've not chased this yet but if I find a work around I'll post it here. I seem to be moving towards editing with textmate rather than in the terminal for messages etc (# is important for github/lighthouse commit message integration).

Line wrapping quirk

Try using ctrl a and cmd left on a line which TextMate has wrapped across two or more lines, you'll see that one goes to the actual start of the line, and one goes to the start of the line you can see on screen.

Go To File

cmd t

This is nothing like your usual file open dialogue, it's more like Spotlight and you should try it out. If you know the filename you want it'll take you straight there, no path navigation.

It also adapts to your usage over time, and you can do things like assign abbreviations just by using them then selecting what you want the first time or two to train it.

Go To Symbol

shift cmd t

This means 'go to function', 'go to section', 'go to chapter', and so on depending on what language or mark-up you are editing.

If your language's grammar is supported by TextMate so that it has 'symbols' you can use both the menu to the bottom right of the edit window, and this dialogue to go to where you want to be. It works just like the go to file menu.

Cheat Sheet

I've not decided how I'm going to format or produce this yet so it'll appear with the next installment.

Leave a Reply