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)

Creating projects (Must know)

This task will cover creating and saving projects through various methods, including opening directories, drag-and-drop, and by using the command line.

Getting ready

If you would like to use the drag-and-drop to dock method, you will need to copy the TextMate application to the dock.

If you would like to use the command-line method, you will need to install the mate command-line executable, which you are prompted to do during the first run of TextMate. You may also install it from the File menu (select Help | Terminal Usage…) at any time. See the Configuring TextMate section explained earlier in the chapter, for more information.

How to do it...

Let's cover the typical ways to create projects in TextMate:

  • Create a new project through the menu (select File | New Project) or with the keyboard shortcut (Command + Control + N). You can then add files to it by dragging and dropping from the Finder or by adding existing files from the Project Drawer toolbar, as shown in the following screenshot:

  • Opening a folder or multiple files will also create a project. You can do this from the menu by selecting File | Open (Command + O).

  • Dragging and dropping a folder or multiple files to a TextMate dock item will open those files into a new project. This is shown in the following screenshot:

  • Command line is also available if you're comfortable in the Terminal. You can create new projects via the mate shell command. Some examples are as follows:

    mate howto.txt notes.txt  # Open multiple files
    mate textmate-howto/      # Open a folder 
    mate .                    # Open current directory

How it works...

Projects allow you to quickly work with multiple files. Once created, you can quickly search for and open files (see the Traversing Files section), create new files, organize files into groups, create project-specific shell variables, and more.

Once you open a project, you can easily save it by selecting File | Save Project (Command + Control + S) or by selecting File | Save Project As… (Command + Control + Shift + S). The latter will allow you to rename a previously saved project.

There's more...

Let's cover how to exclude files or folders from your projects, as well as why you may want to do so.

Excluding files

Sometimes excluding files will speed up search time, for example, if your project includes long logfiles with the extension .log. Unfortunately, the process to exclude files requires knowledge of regular expressions, which is a bit out of the scope of this book.

However, you can find where to exclude files by going to File | Preferences (Command + ,), navigating to the Advanced tab, and selecting the Folder References section. There you will edit the File Pattern and Folder Pattern fields:

Taking the example I gave previously regarding excluding any files with the extension .log, the File Pattern field would look as follows:


Note the |\.log at the end. If you aren't familiar with regular expressions, note that this says to exclude files that end in .log (along with excluding .htaccess, files ending in .tmproj, .o, .pyc, and so on).