Book Image

TextMate How-To

By : Christopher J Mears
Book Image

TextMate How-To

By: 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)

Configuring TextMate (Must know)


This task will quickly go through some of the more helpful configuration options, including some Preference and View settings. Note that these settings are purely my preferences and are only meant to show where to find them. You should set up TextMate however you feel comfortable, and based upon your particular project.

How to do it...

To configure Line Numbers:

  1. From the menu, select View | Gutter | Line Numbers (Option + Command + L) to toggle them on and off.

To configure Soft Tabs:

  1. From the status bar, located at the bottom of the document window, click on the Tab Size pop-up menu, and select Soft Tabs.

  2. From the same pop-up menu, select the desired tab size (usually 2 or 4).

To configure Soft Wrap:

  1. From the menu, select View | Soft Wrap (Option + Command + W).

  2. To choose the width of the wrap, from the menu select View | Wrap Column. Selecting Use Window Frame will change the wrap width depending on the overall width of the document window.

To configure the Show Invisibles option:

  1. From the menu, select View | Show Invisibles (Option + Command + I). Two examples are shown in the following screenshot:

To configure Check Spelling as You Type:

  1. From the menu, select Edit | Spelling | Check Spelling as You Type (Option + Command + ;).

Selecting Highlight current line, Show right margin indicator, and Highlight right margin:

  1. From the menu, select TextMate | Preferences (Command + ,).

  2. In Preferences, under the General tab, check Highlight current line, Show right margin indicator, and Highlight right margin.

How it works...

Now, let's go through why you may want to use these settings:

  • Line Numbers: They are helpful to establish where you are in a document. If you'd rather have fewer margin distractions, then you can also determine your cursor's current line and column position in the status bar at the bottom of the document window.

  • Soft Tabs: Soft tabs versus hard tabs are somewhat controversial (do a Google search and you'll see). You should really use what you're most comfortable with or what conforms to the project or document style rules.

  • Soft Wrap: This will wrap lines based on your margin column width settings. If this is not set and there's a line that goes beyond the document window's view, scrolling will be necessary to view the rest of the line.

  • Show Invisibles: This will show tabs and line returns. Sometimes, this is helpful for troubleshooting some oddities in your document, such as why a tab isn't lining up properly. They are also helpful to get a complete picture of your code. However, if you would rather not have the clutter, it's perfectly reasonable to turn this setting off.

  • Check Spelling as You Type: This will provide the familiar wiggly red line under misspelled words. Right-clicking on the words will provide alternate word options. It's only necessary when composing written words, but TextMate is smart enough to determine when you're writing code and won't try to spell check everything.

  • Highlight current line: This will provide a horizontal highlight to indicate in which line your cursor is located. The right margin indicator option will provide a vertical line to indicate the right margin, and the Highlight right margin option will highlight the right margin. These visual indicators, or ornaments, will help show you where your cursor is in the document, as well as where the right margin is located. Knowing where the right margin is can be helpful for keeping code readable and well styled. For example, if some of your fellow coders are accessing the files via shell editors (that is, vim, emacs, nano, and so on), they may have limited document width based on their particular terminal program.

There's more...

Included with the TextMate application is a command-line tool, which can be used in Terminal to open files. In addition, it's quite important to learn the keyboard shortcuts, which will help you do things quickly and efficiently. However, in order to learn the shortcuts, it is vital to learn what the keyboard symbols look like.

Enhanced Terminal Usage

When you run TextMate for the first time, you will be prompted to install the shell command mate. Installing this tool will allow you to open files into TextMate from Terminal, for example, mate example.html or mate project/. There is more on opening files in the Traversing files recipe.

You can open the install dialog at any time from the menu; select Help | Terminal Usage.

Keyboard shortcuts

TextMate is most powerful when you use keyboard shortcuts as opposed to reaching for the mouse and selecting menu items. This How-To will try to provide the keyboard shortcuts for as many of the functions as possible.