Skip to content

Instantly share code, notes, and snippets.

@fonnesbeck
Created January 12, 2015 15:16
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/c81ea6b92e2e0b6d06db to your computer and use it in GitHub Desktop.
Save fonnesbeck/c81ea6b92e2e0b6d06db to your computer and use it in GitHub Desktop.

Power Text Editing using 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 ctrl-cmd-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 ...

ctrl-H will pull up relevant documentation in most bundles.

There are a variety of bundles maintained on GitHub.

Column selection

Select rows with mouse, click option

Alternately, hold downoption while interactively making a selection.

Multiple carets

Edit multiple arbitrary locations simultaneously

To edit all occurrences of a particular string:

  • select string
  • cmd-E to use selection for find
  • option-cmd-F to find all

Incremental search

Quickly search current document for a string with control-s.

Text tools

  • typing any open bracket character when text is selected will put those brackets around the text
  • ctrl-W selects the current word (hitting it again adds the next occurrence to the selection)
  • shift-cmd-L selects an entire line
  • ctrl-shift-K deletes an entire line
  • ctrl-K deletes to the end of a line
  • ctrl-shift-J merges the current line with the previous one
  • ctrl-cmd-{arrow} moves a particular line in given direction
  • cmd-leftarrow (cmd-rightarrow) moves to the beginning (end) of the line
  • cmd-uparrow (cmd-downarrow) moves to the top (bottom) of the document
  • opt-leftarrow (opt-rightarrow) moves to the left (right) one word at a time
  • opt-cmd-[ automagically cleans up indentation
  • cmd-/ comments out the current line according to appropriate language
  • ctrl-shift-underscore toggles between CamelCase, underscores and nerdCase

TextMate also recognizes Emacs shortcuts.

Clipboard history

You can access the recent history of your clipboard using ctrl-opt-cmd-V.

Opening TextMate from the Terminal

Opening TextMate via mate command.

File diffs can be piped to TextMate, and displayed with highlighting.

 diff file1.py file2.py | mate

Can set up rmate to edit remote files.

File browser

When working with multiple files (project) its useful to display the file browser pane (ctrl-opt-cmd-D).

  • browse, open, create files
  • 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 cmd-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.

You can open recent projects or your favorites with shift-cmd-O

Git support

The Git bundle provides access to most routine Git commands. cmd-Y opens a contextual menu; can search for commands with the Select bundle item ... pane (ctrl-cmd-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.

Contextual help

For many language bundles, ctrl-H will display help for the current command in your code, provided that it is available...`

Drag commands

Dragging images into an html or markdown document.

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