I’m going to cover a few general tips for text editing – I’ll split them into parts since there will be quite a few to cover, so this one will focus on moving around and selecting stuff.
Now, hopefully most of you know that option-left/right can be used to move the caret one word to the left or right (if you don’t, then this is a system-wide feature, so you can use it almost anywhere). A less known alternative available in TextMate is using control with the left or right arrow keys – this works as a less “greedy” version, and is especially useful when working with camelCased and snake_cased words. For example, say we have
NSString‸ and wish to change it to
NSMutableString: we can just use
⌃← to move the caret after
NS and then type to insert
Mutable. Of course, you can also use
⌃ in instances where you would use
⌥ when modifying the selection, deleting words etc. – here we could have used
⌃⌫ to get just
Modifying the selection
TextMate adds a few ways to select items – for example you can select the current word with
⌃W, the current line with
⇧⌘L (take a look in the Edit → Select menu for more).
An interesting one is “Current Scope” –
⌃⌥B. The best way to predict how this will work is to experiment; the exact behaviour will depend on the current language definition, but it’s very handy for selecting strings, comments and other entities – you can press this a few times to grab more of the surrounding text, and some languages will allow you to grab the contents of a string first, and then the contents with the surrounding quotes next.
Moving the selection
You can move the current selection around in the document by using
⌃⌘ and an arrow key (this is handy for swapping lines, re-arranging code etc.). – it also works with columnar selections.
More to come (I’ll be happy to field subject requests too).
6 Responses to “TextMate Tip – Moving and Selecting”