TextMate Tip – Moving and Selecting
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.
Sub-word movement
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 NS.
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).
Ciaran, Regarding the ^ arrow feature in TM, is there a way to change the binding? If you’re using leopard with Spaces, if you use ^ left or ^ right arrow, you’re actually switching spaces…
Atleast that’s what’s happening on my macbook pro. I know you can change the setting in spaces, but is there a way to tell TM to use something else? I like the way I change spaces
.
I just changed the keybinding for Spaces, since I am so used to using ⌃← in TM. It should be possible to change it though, see the TextMate Help. Take a look at the 4th paragraph, basically you’ll want to copy the file to your app support directory and edit the
moveSubWordselector keybindings. This post has more info on how to do that.Try arranging your spaces in a single vertical column, so that only ⌃↑ and ⌃↓ are used. This is also a much smoother way to arrange spaces if you have multiple physical monitors arranged horizontally.
David, Thanks for the excellent tip.. not sure why I didn’t think of it myself
.
makes life much simpler.
These tips are great, all of them! About current scope selection – where is that defined? I’m using python and would like to add some “features” to this selection mode if possible…
great tips thanx… textmate, macos, they all have lotsa lotsa keyboard shortcuts and its realy hard for me to memorize all (8… i’ll find a way to do it… try to enhance my nmonic devices (8