Skip to content

Instantly share code, notes, and snippets.

@fonnesbeck
Created November 1, 2015 22:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fonnesbeck/e856a98d6e1ac93cdcba to your computer and use it in GitHub Desktop.
Save fonnesbeck/e856a98d6e1ac93cdcba to your computer and use it in GitHub Desktop.

Effective Text Editing with TextMate

Bundles

Installed via Preferences > Bundles

Bundles are typically associated with particular file types, and will automatically load when a file of that type is opened.

You can trigger bundle items via the Select bundle item widget using ⌃⌘T, then entering text to find what you're looking for.

Bundle items are also available via the "gear" icon on the status bar.

You can customize and installed bundle via the Bundle Editor: Bundles > Edit Bundles ...

⌃H will pull up relevant documentation in most bundles.

Column selection

Select rows with mouse, click

Alternately, hold down while interactively making a selection.

Multiple carets

Edit multiple arbitrary locations simultaneously

To edit all occurrences of a particular string:

  • select string
  • ⌘E to use selection for find
  • ⌥⌘F to find all

Incremental search

Quickly search current document for a string with ⌃s.

Text tools

  • typing any open bracket character when text is selected will put those brackets around the text
  • ⌃W selects the current word (hitting it again adds the next occurrence to the selection)
  • ⌃⇧K deletes an entire line
  • ⇧⌘L selects an entire line
  • ⌃K deletes to the end of a line
  • ⌃⇧J merges the current line with the previous one
  • ⌃⌘{arrow} moves a particular line in given direction
  • ⌘ ← (⌘ →) moves to the beginning (end) of the line
  • ⌘ ↑ (⌘ ↓) moves to the top (bottom) of the document
  • ⌥ ← (⌥ →) moves to the left (right) one word at a time
  • ⌥⌘[ automagically cleans up indentation
  • ⌘/ comments out the current line according to appropriate language

TextMate also recognizes Emacs shortcuts.

Clipboard history

You can access the recent history of your clipboard using ⌃⌥⌘ V.

Opening TextMate from the Terminal

Opening TextMate via mate command.

Can set up rmate to edit remote files (see below).

File browser

When working with multiple files (project) its useful to display the file browser pane (⌃⌥⌘D).

  • browse, open, create files
  • store favorites (view Favorites via ⇧⌘O)
  • version control information
  • open Terminal in file location

Auto-complete and snippets

ESC is your friend. Hitting it repeatedly will cycle through completion alternatives based on current document

  • project-level completion is possible, using ctags (beyond scope of this tutorial)

Most bundles include context-specific "snippets" of commonly-used language constructs. They are triggered with a keyword followed by tab.

Advanced find-and-replace

TextMate's find interface can search across and entire project, and optionally use regular expressions.

The preview pane shows what your replacement would look like before committing to the changes.

Search can be performed in one of several scopes:

  • selection
  • file
  • project/folder

Go to file

Pressing ⌘T opens the "Go to file" dialog that allows you to find particular files within the current file (folder). Typing a few characters does a live search of that substring.

Git support

The Git bundle provides access to most routine Git commands. ⌘Y opens a contextual menu; can search for commands with the Select bundle item ... pane (⌃⌘T).

The Gist command is useful for sharing code and snippets via your GitHub accounts. Gists can be updated with a single command.

Latex support

The LaTeX bundle in TextMate includes several actions and snippets to help you automate your workflow.

TextMate interacts with your specified LaTeX viewer.

Edit files on remote servers from the comfort and convenience of TextMate! The rmate script will run on the remote machine and send files to TextMate for manipulation over a SSH connection.

Setting up rmate involves:

  1. Copying the rmate script to your remote machine.
  2. Enabling rmate connections on a chosen port in the Terminal preferences.

You can then use an SSH tunnel to connect to your server:

ssh -R 52698:localhost:52698 user@example.org

Calling rmate <filename> from that machine will open <filename> in TextMate on your local machine.

Spell checking

You can step through your document and check for spelling errors by pressing ⌘;. This will present spelling suggestions (if available) and allow you to add words to the dictionary. Importantly, the spell checker will recognize and ignore code if you are in a coding syntax.

TODO bundle

For large documents or projects, I often leave TODO and FIXME comments to remind me about things. The TODO bundle in TextMate searches the current project tree for comments with TODO, FIXME, CHANGED and RADAR and displays them in the output window. Just hit ⌃⇧T. You’ll never forget again.

To add your own markers, go to the cog menu, find the TODO bundle and click Preferences. Add a new marker and replace the regular expression to catch the rest of the comment. Hit Done, restart TextMate and run TODO again to see your new marker matches.

Variables and .tm_properties

Several preferences can be stored in your .tm_properties file

# Universal settings
fontName           = "Source Code Pro"
fontSize           = 16
lineHighlight      = '#FFFBD1';

softWrap           = true
wrapColumn         = "Use Window Frame"
tabSize            = 4
softTabs           = true

excludeFiles       = "*.{so,pyc,o}"
excludeDirectories = "{build,dist,*.egg-info}"
includeFiles       = ".gitignore"

spellChecking      = true

TM_GIT             = "/usr/local/bin/git"

PATH               = "$PATH:/usr/texbin"

# Add Git info in window title
windowTitleSCM     = '${TM_SCM_BRANCH:+ ($TM_SCM_NAME: $TM_SCM_BRANCH)}'
windowTitle        = '$TM_DISPLAYNAME$windowTitleSCM'

# File-specific configurations
[ source.python ]
TM_PYCHECKER       = pep8
spellChecking      = false
TM_PYCHECKER       = /usr/local/bin/pep8

[ .git/COMMIT_EDITMSG ]
spellChecking      = true
spellingLanguage   = 'en'

[ *.{icns,ico,jpg,jpeg,m4v,nib,pdf,png,psd,pyc,rtf,tif,tiff,xib} ]
binary             = true

[ "{README,INSTALL,LICENSE,TODO}" ]
fileType           = "text.plain"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment