Book Image

TextMate How-To

By : Chris Mears, Christopher J Mears
Book Image

TextMate How-To

By: Chris Mears, Christopher J Mears

Overview of this book

Not all text editors are created equal. TextMate was created with versatility and power to the developer. Whether you want to organize your files in projects, utilize the efficiency of code completion, take advantage of the thousands of publicly available bundles, or gain insight using powerful regular expression searching, TextMate is an essential and easy-to-use tool you need in your development arsenal. "TextMate How-To" is a practical guide filled with conventional recipes on using one of the most popular text editors on the OS X platform. It is a great resource for anyone who wants to learn how to code more efficiently and effectively, no matter what programming or scripting language you use. This book will guide the reader through using TextMate for practical purposes. It will start with configuring the application, then cover navigation and editing of files, and finish with bundles and advanced features. Throughout the book, the reader will quickly master the key features of the application through easy to follow tasks. Using this book, the reader will learn the most common text editing and coding tasks including navigation through the document and searching of text. The reader will then learn about working with and navigating between files and projects as well as utilizing bundles to greatly speed up development. Finally, explore the ability to use shell commands and macros to increase productivity. With just a few hours, "TextMate How-To" will teach the reader everything necessary to hit the ground running with this powerful text editor.
Table of Contents (7 chapters)

Quickly navigating to text (Must know)

This task will show you how to navigate the document and text, in most cases without reaching for the mouse or track pad.

How to do it...

The two available options to quickly navigate to the text are as follows:

  • Go to Line... will move your cursor to the specified line number. From the menu, select Navigation | Go to Line… (Command + L).

  • Go to Symbol... will move your cursor to the beginning of a function, method, or other symbol. From the menu, select Navigation | Go to Symbol… (Shift + Command + T).

How it works...

Go to Line... (Command + L) is very useful for situations where you know the precise line you want to edit. For example, when you're debugging some code and the error message code gives the problem line number.

Go to Symbol... (Shift + Command + T) is mainly used for programming languages such as JavaScript and PHP, where functions or methods are defined in the document. When this is invoked, a window will appear with the names of the functions or methods available, as shown in the following screenshot:

Start entering the method name and it will match and filter the list based on what you enter. Go to Symbol... (Shift + Command + T) is extremely helpful for long documents of code where scrolling and navigating line by line is unreasonable.

You can also open the function pop up in the status menu (located at the bottom of the document window) to display all of the functions or methods in your document. This is shown in the following screenshot:

There's more...

Along with the quick navigation shortcuts, there are also ways to move the cursor and scroll the document easily without using the mouse.

Cursor movement

The following keyboard shortcuts will move your cursor:



Shift + F

One character forward.

Shift + B

One character backward.

Shift + P

Up one line.

Shift + N

Down one line.

Shift + A

Beginning of line.

Shift + E

End of line.

Option + right arrow

Right one word (Mac convention).

Option + left arrow

Left one word (Mac convention).

Note that the first four movements can be accomplished by using the arrow keys, but sometimes it's faster to keep your fingers on the keyboard home row.

Scrolling the document without moving the cursor

In the situation where you want to take a peek within the document without moving the cursor, you can use the keyboard shortcut Command + Option + Control plus the arrow keys. For example, to scroll up, you would press Command + Option + Control + up arrow. Your cursor will stay put and you can go back to it by using the Command + J (that is, select Edit | Find | Jump to Selection) keyboard shortcut.