textmate操作手册
Table of Contents
1 Preface1.1 About the DocumentationThe intended purpose of the documentation is to explain the main
features of TextMate and to highlight features that may not be obvious
to first time users. The documentation is not exhaustive.
You should have a good understanding of what a text editor is, in
particular you should have some experience with Cocoa's text edit
control (used in TextEdit, Mail and Xcode). While TextMate does not use
that control, it does mimic its behavior for the most part.
If you want to print this documentation then here is a printable version.
1.2 Philosophy of TextMateFrom UNIX we get that Tasks and Trends Change. In concrete
terms this means that instead of writing a command (in UNIX) to solve
the problem at hand, we find the underlying pattern, write a command to
solve problems of that type and then use that command in a script.
This gives us a command which we can re-use in the future for
multiple problems of the same type. Since it is generally much easier
(and more flexible) to piece together a script of different commands
than it is to write a specific command the increase in productivity can
be very large. This is especially true since we do not actually write
the command in the first place, we use an existing command that has
already been written for this type of problem.
There are two ways in which TextMate leverages that philosophy.
First it has good shell integration, so if you are skilled in using the
UNIX shell, you should love TextMate.
But more ambitiously, TextMate tries to find the underlying patterns
behind automating the tedious, being smart about what to do and then to
provide you with the functionality so that you can combine it for your
particular needs.
Granted, TextMate is not the first text editor which tries to be broad, but from Apple we get the venerable Keep It Simple.
So even users with little or no experience with scripting and regular
expressions are able to customize TextMate in ways that no other editor
would have allowed them to.
Having said that, the philosophy of TextMate is also to Educate the User. So to fully capitalize on what TextMate gives you, you should learn about regular expressions, you should understand TextMate's scope, snippet system (also language grammars to some degree) and have an idea about the shell infrastructure provided (in particular environment variables, pipes and stdin/stdout).
1.3 TerminologyFor the most part TextMate and this documentation abides by Apples terminology. Below is a table of terms that might be a source of misunderstanding.
Generally TextMate and this documentation use the glyph
representation of a key. Below is a table with most glyphs, the name of
the key (as used in this documentation) and a short explanation.
![]() If you are unsure about the location of a key, you can bring up the Keyboard Viewer, which you can add to the Input menu in the International pane of System Preferences.
1.4 LimitationsTextMate is a work-in-progress. One current key limitation (for
non-Western users) is support for international input modes (e.g. CJK),
proportional fonts, right-to-left text rendering and other (UniCode)
features. As the author, I do understand the desire from users to have
TextMate support these things, but currently proper support for this is
a long-term to-do item.
And on the topic of limitations, I am also aware of the desire for
(s)ftp integration, code hinting, split views, better printing,
indented soft wrap, coffee making and literally hundreds of other user
requests. You will be able to find my comments on most feature requests
by searching the mailing list archive, but I do not give estimates or timeframes, other than what version number I plan for something to appear in.
2 Working With Multiple Files2.1 Creating Projects (With Tabs)In the current version of TextMate (1.5) file tabs are only
supported when a project is created. Fortunately it is easy to create a
project, namely by selecting File → New Project (⌃⌘N).
This opens a window which looks like the one below.
![]() It is possible to add files either by dragging them to the (project)
drawer, or use the “Add Existing Files…” action in the project drawers
action menu (the one with the gear icon).
Another way to create a project is by dragging files directly onto
the TextMate application icon (shown e.g. in the dock). This is a
shortcut for creating a new project consisting of these files.
One minor detail is that when creating a project this way, you will
not be asked if you want to save the project, when it is closed.
The advantage of saving a project is to maintain state (e.g. which
files were open) and to be able to quickly re-open a particular set of
files. If you leave a (saved) project open when you quit TextMate, it
will automatically re-open that project the next time you launch
TextMate.
It is also possible to create projects from the terminal e.g. using the
mate shell command.2.1.1 Auto-Updating ProjectsWhen you want to have your project mimic the files and folders on
disk, you can drag a folder either onto the TextMate application icon,
or into the project drawer.
TextMate will then create a folder reference where it automatically updates the contents of the folder when it changes on disk.
![]() Currently updating is done when TextMate regains focus and can be
slow for some network mounted disks, in which case you may want to
settle for only adding individual files to the project (which can be
grouped and re-ordered manually to mimic the structure on disk).
The refresh delay for network mounted disks will be addressed in a future release.
2.1.2 Filtering Unwanted FilesWhen using folder references, you may want to have certain files or
folders excluded from the project. This can be done by changing the
file and folder patterns found in Preferences → Advanced → Folder
References.
![]() These are regular expressions which are matched against the full
path of each file and folder. If the pattern does match the item, it is
included, otherwise it is excluded. To reverse that, so that items
which match are excluded from the project, prefix the pattern with an
exclamation point (
!).The patterns are only used when creating new folder references. For
existing folder references one can select the folder reference in the
project drawer and use the info button (a circled letter I) in the
project drawer to edit the patterns.
The complexity of this system will be addressed in a future release.
2.1.3 Text and Binary FilesYou can either single or double click files in the project drawer.
If you single click them and the file type is text, they open as a file
tab in the main window.
If you double click a file, it will open using the default
application. Note that folders can also be double clicked e.g.
Interface Builder’s nib files will appear as folders, but can still be
double clicked (and will then open in Interface Builder).
As mentioned, only text files will open in the main window when
single clicked. The way TextMate determines if a file is text is by its
extension - if the extension is unknown it scans the first 8 KB of the
file to see if it is valid UTF-8 (which is a superset of ASCII).
If TextMate does not open your file and it does have an extension
you can bring up the action menu for that file and pick the last item,
which should read: Treat Files With “.«ext»” Extension as Text.
2.1.4 Positioning the Project DrawerThe project drawer will by default open on the left side of the
project window. If there is no room for it to open there, it will use
the right side instead. This setting is sticky so will remember which
side the project drawer was last opened on.
![]() To move it back to the left side you need to close the drawer (View
→ Hide Project Drawer) and then move the project window so that there
is no longer room for the drawer on its right. When you then re-open
the drawer, it will again appear on the left side and use that as the
new default.
The opposite can be done to force it to open on the right side.
2.2 Find and Replace in ProjectsUsing Edit → Find → Find in Project… (⇧⌘F) will bring up the window shown below.
![]() From here it is possible to search all (text) files in the current
project and do replacements. After pressing Find it is possible to
either press Replace All, or select which matches should be replaced,
in which case the Replace All button will change to Replace Selected.
Currently it is not possible to limit the scope of the search to
anything other than all text files in the full project. As a
workaround, when you want to search only a subset of your project, you
can select the files you want to search in the project drawer and drag
the selection to the TextMate application icon to create a new scratch
project. A find/replace can then be performed on that project, which
can then be closed.
2.3 Moving Between Files (With Grace)When working with projects there are a few ways to move between the open files.
The most straightforward way is by clicking on the file tab you
need. This can also be done from the keyboard by pressing ⌘1-9, which
will switch to file tab 1-9.
You can also use ⌥⌘← and ⌥⌘→ to select the file tab to the left or right of the current one.
It is possible to re-arrange the file tabs by using the mouse to
drag-sort them (click and hold the mouse button on a tab and then drag
it to the new location). This should make it possible to arrange them
so that keyboard switching is more natural.
One more key is ⌥⌘↑ which cycles through text files with the same
base name as the current file. This is mainly useful when working with
languages which have an interface file (header) and implementation file
(source).
When you want to move to a file which is not open you can use the Go
to File… action in the Navigation menu (bound to ⌘T). This opens a
window like the one shown below.
![]() This window lists all text files in the project sorted by last use,
which means pressing return will open (or go to) the last file you
worked on. So using it this way makes for easy switching to the most
recently used file.
You can enter a filter string to narrow down the number of files
shown. This filter string is matched against the filenames as an
abbreviation and the files are sorted according to how well they match
the given abbreviation. For example in the picture above the filter
string is
otv and TextMate determines that OakTextView.h is the best match for that (by placing it at the top).The file I want is
OakTextView.mm which ranks as #2.
But since I have already corrected it in the past, TextMate has learned
that this is the match that should go together with the otv filter string, i.e. it is adaptive and learns from your usage patterns.3 Navigation / Overview3.1 BookmarksIf you need to move the caret to somewhere else in your document and
want a quick way to return, you can place a bookmark on the current
line.
This is done either by clicking in the gutter (in the column
dedicated to bookmarks) or pressing ⌘F2. The bookmark will be indicated
with a star as shown below.
![]() When you want to return you can press F2, which moves you to the
next bookmark in the document. If there is more than one bookmark, you
can press F2 repeatedly. ⇧F2 will move to previous bookmark.
3.2 Collapsing Text Blocks (Foldings)When working in a language which has start/end markers for blocks, like
{ … }, do … end, <tag> … </tag> and similar, TextMate can spot these blocks and will show up/down arrows in the gutter beside the start/end marker.When these arrows are present, it is possible to fold the block into
a single line either by using the mouse and clicking on the up/down
arrow, or pressing the F1 key. This will make the arrow in the gutter
point to the right and indicate that the entire block was folded by
placing an ellipsis marker at the end of the line. An example where the
two sub-blocks of the constructor has been folded can be seen below.
![]() With text folded, it is possible to unfold it with F1 or clicking
either the arrow in the gutter or the ellipsis image. It is also
possible to hover the mouse pointer on the ellipsis image to get a tool
tip which shows the contents of the folded block. The latter is shown
on the following picture.
![]() A word of caution: the folding system is based on both having clear indent markers and
having the fold start/stop markers use the same indent level. This
means that folding based purely on indent or where the start/stop
markers do not align, is currently not supported.
3.2.1 Customizing FoldingsAs mentioned the folding system uses explicitly defined start and stop markers. TextMate knows about these from the language grammar where you can setup a
foldingStartMarker and foldingStopMarker regular expression.![]() Shown above are the HTML folding patterns, which are all relatively
simple because they fold on a selected set of tag pairs, HTML comments,
some Smarty tags and start/stop braces when either last on the line or
used in embedded code tags like this:
To define a block that starts with
{ as the last non-space character on the line and stops with } as the first non-space character on the line, we can use the following patterns:
3.3 Function Pop-upFor languages that support it, the rightmost pop-up in the status
bar shows the current “symbol” (often the function prototype or heading
above the caret).
It is possible to click on the pop-up to get a list of all the
symbols in the current document and move the caret to one of these.
This is shown below.
![]() For keyboard navigation there is also Navigation → Go to Symbol…
(⇧⌘T) which opens a panel like the one shown below. The contents of
this pane are the same as the pop-up from the status bar but this panel
supports filtering similar to the Go to File… panel
(i.e. where the filter string is treated as an abbreviation and matches
are ranked according to how good a fit the abbreviation seems to be).
![]() The panel can be left open and will automatically update as the
document is edited. If you single-click an item in the list, the caret
will move to the symbol clicked. Double-clicking will do the same but
also closes the panel.
3.3.1 Customizing the ListThe symbol list works using language grammars and scope selectors.
A language grammar assigns names to each element in the document and a
scope selector is capable of targeting a subset of the document based
on these names. Normally the parallel is HTML and CSS, e.g. we can make
a theme item
which sets the background to blue and then use the scope selector to
pick which elements in our document we want this theme (and hence the
blue background) applied to.
Bundle preferences
work like theme items, except that instead of changing visual settings
they (generally) change non-visual settings. One exception is the
showInSymbolList. By setting this to 1
and using a scope selector which (for example) targets all function
names, we are using that scope selector as a query to extract all the
function names from the document, for use in the symbol list.So to populate the symbol list we need to:
In addition to the
showInSymbolList setting there is a symbolTransformation
setting which is one or more regular expression substitutions which are
performed on the text extracted. The value of this setting should be: s/«regexp»/«format»/«options» optionally followed by ; and more substitutions. It is also possible to put comments in the value, these start with # and end at the next newline.So if we want to show Markdown headings in the list, which are lines that start with one or more
# marks, then we first make sure our language grammar
assigns a name to these, for Markdown that can be identified with this
rule, by specifying the following in the language grammar:
Now we can target all headings using a scope selector of
markup.heading.markdown. We can now create a bundle preferences item that is simply:
This will include the leading
# marks in the list,
which is undesirable. We can either assign a name (via the language
grammar) to the actual title, or we can perform a regular expression
substitution to get rid of the leading # marks. The
latter has the advantage that we can change these to indent, so that is
what we do, by changing the preferences item to:
4 Working With TextTextMate tries for the most part to mimic the behavior of the
NSTextView system component, as used by applications such as Mail, Safari and basically all other Cocoa applications.Some of the extra features related to text editing are covered in this section.
4.1 Auto-Paired Characters (Quotes etc.)When writing structured text (like markup or source code) there are
characters which go together in pairs. For example in a programming
language you rarely type an opening brace (
{) without also needing the closing brace (}).To help you keep these characters balanced, TextMate will insert the
appropriate closing character after the caret when you type the opening
one. If you type the closing character TextMate is smart enough to
overwrite the auto-inserted one. If you type an opening character and
then delete it using backward delete (⌫) then the auto-inserted
character will also be deleted. If you only want to delete the
auto-inserted character, use forward delete instead (⌦).
It is also possible to wrap a selection in an open/close character
by selecting text and typing the opening character. For example if you
type
foo, select it and type ( then TextMate will make it (foo) placing the caret after the ending parentheses.The actual character pairs are defined in the bundle preferences
with different settings for different languages and contexts. For
example, in source code an apostrophe is set up to have itself as a
closing character, except for comments and strings. This is achieved
using scope selectors.
Two useful shortcuts in relation to auto-paired characters (defined as macros in the Source bundle and overridden for a few languages) are:
4.2 CompletionTextMate has a simple yet effective completion function on ⎋
(escape). It will complete the current word based on matches in the
current document. If there are multiple matches, you can cycle through
these by pressing ⎋ continuously. It is also possible to cycle
backwards using ⇧⎋.
The matches are sorted by distance from the caret, meaning
candidates which are closer to the caret will be suggested before
candidates farther away.
Two possibilities exist for augmenting this default completion. Both are done via bundle preferences.
The first option is to provide a list of candidates which should
always be suggested. For example the Objective-C bundle has a list of
commonly used Cocoa framework methods. This is an array of the
candidates, e.g.:
The other option is to set a custom shell command to gather the completions. The shell command will have the
TM_CURRENT_WORD environment variable available (as the word which needs to be completed) along with the other variables.For example the C bundle has a custom completion command setup for
when the caret is inside the preprocessor include directive, it looks
like this:
This will find as matches, any file in the current directory (and
direct sub-directories) which have the current word as prefix and an
.h extension.When you provide your own completion command (or list) you may want to disable the default matches. This can be done by setting
disableDefaultCompletion to 1.4.3 Copy and Paste4.3.1 Clipboard HistoryEach time you copy or cut text, the text is pushed onto a stack.
By pressing ⌃⌥⌘V you will see the list of all previous clippings and
can pick the one you want to paste using arrow keys. Use return to
insert it and escape to dismiss the list. If you dismiss the list, the
currently selected clipping will be what gets pasted the next time you
use the paste function.
![]() Instead of having to pick the clip from the list, you can use ⇧⌘V to
paste the previous clip in the list. Using that key again will advance
to the clip before that and so on. To go back you can use ⌥⌘V. These
key equivalents are useful when you want to make multiple copies from
one document and then paste these LIFO-style (Last In First Out) into
another document (or another location in the same document).
4.3.2 Re-indented PasteWhen pasting text, TextMate will estimate the indent of the text
pasted as well as the current indent level and adjust the pasted text
so that it matches the current indent.
The estimates are done using the indentation rules mentioned in the Re-Indent Text section.
If you temporarily want to avoid this you can paste text using ⌃⌘V.
You can also permanently disable re-indented pasting in the Text
Editing part of the Preferences.
4.4 Editing Modes4.4.1 Freehanded EditingYou can enable or disable freehanded editing in the Edit → Mode submenu (⌥⌘E).
With this mode enabled caret movement will not be restricted by line endings or tab stops.
This is useful when working with ASCII diagrams, when inserting
something at a given column on several lines (and you do not want to
insert the padding) and in a few other situations.
When making column selections freehanded mode is (temporarily) enabled, allowing you to make selections past the end of lines.
It is also possible to place the caret beyond the end of a line by
single-clicking the mouse while holding down the option key (⌥).
4.4.2 Overwrite ModeBy enabling overwrite mode in the Edit → Mode submenu (⌥⌘O)
characters already in the document will be overwritten as you type
rather than inserted as normal.
This is useful when working with column data, e.g.:
Imagine we want to overwrite some of the values in the first column.
Somewhat similarly, we may have a line of a fixed width and want to
replace part of it but preserve the width, for example we could have
code like this where we must right-align the value to column 20 but
want to overwrite the label:
4.5 Find and ReplaceIn addition to the standard find dialog, TextMate has a Find submenu
(located in the Edit menu) which gives you key equivalents for find and
replace actions.
![]() 4.5.1 Inserting Newlines and Tabs in the Find DialogThe find dialog uses normal system controls for accepting input. You
can toggle between single line and multi line text controls using the
arrow next to the Replace text field.
![]() If you need to insert a newline or tab character into either of the
text fields, you can hold down option (⌥) while pressing the tab (⇥) or
return (↩) key. This will insert a literal tab or newline character.
4.5.2 Find ClipboardTwo useful key equivalents are ⌘E and ⌘G. The first copies the
selection to the shared find clipboard. This works in the majority of
applications and allows you to find the next occurrence of that string
by then pressing ⌘G.
The find clipboard works across applications so whether in Safari,
TextEdit, Mail, TextMate, Terminal, Console, or similar, one can copy
the selected text to the find clipboard, switch application and use ⌘G
to find that string.
In addition TextMate offers ⇧⌘E to copy the selection to the replace
clipboard. This is often useful to save a trip to the find dialog, for
example if you want to replace newlines with the pipe character (
|) for a list of items, select a newline, press ⌘E to use that as the find string. Now type a |, select it and press ⇧⌘E so that it is copied to the replace clipboard.The next step is then to either press ⌃⌘F to perform the replacement
in the entire document, or select the range in which you want the
replacement to occur and use ⌃⇧⌘F instead.
4.6 Moving Text4.6.1 Increase/Decrease Indent LevelIn the Text menu there is a Shift Left and Shift Right action bound
to ⌘[ and ⌘]. These will increase and decrease the indent by the size
of one tab.
On many european key layouts these keys are rather awkward, so in
addition to these, you can also use ⌥⇥ and ⌥⇤ (where ⇤ is achieved
using ⇧⇥).
4.6.2 Move Text Up/Down/Left/RightIf you want to move a line/block up/down a few lines or move a
word/column selection, it can be done by holding down ⌃⌘ and using the
arrow keys to move the selection around. It also works for moving lines
up/down without a selection.
4.6.3 Re-indent TextIf you have code which has broken indent, you can select it and use
Text → Indent Selection (without a selection it indents the current
line).
The rules for estimating the indent are setup per-language using bundle preferences. For more details see the indentation rules section.
4.7 Selecting TextSelecting text is achieved by holding down ⇧ while using the normal
movement keys. In addition the Edit → Select submenu has actions to
select current word, line, paragraph, enclosing brackets and entire
document.
4.7.1 Editing Multiple LinesSometimes there is a need for adding a suffix to lines of variable length, or maybe editing the last part of these lines.
Although you can use find and replace for this, an easier way is to
select the lines that needs to be edited, then use Text → Edit Each
Line in Selection (⌥⌘A) and the caret will be placed at the end of the
first line in the selection.
You can now type new text, delete text or go back and edit existing
text and this will be mirrored down through all the (previously
selected) lines. To leave this mode, simply move the caret away from
the current line.
4.7.2 Column SelectionsIt is possible to select column data either by holding down ⌥ and
making the selection with the mouse, or making a regular selection and
then pressing ⌥ once (which toggles between the two types of selection).
You can use all the normal actions on a column selection e.g. move
selection, replace in selection, transpose (lines), actions from the
Text menu, filter the selection through a shell command, etc.
4.8 Column Movement / TypingUsing arrow up/down with ⌥ will move the caret to the first/last row in the current column. Hold down ⇧ to get it selected.
![]() For example if you have column data as shown above with the caret in front of
foo, press ⌥⇧↓ and it will move the caret down in front of fud and leave the text between foo and fud selected.![]() You may now either want to press ⌥ once to switch to a zero-width column selection, then start typing to type on each line.
![]() Alternatively use ⌥⇧→ and then ⌥ to leave the entire column selected (in column mode).
![]() 4.9 Smart Tab BehaviorWhen using the tab key at the beginning of a line, TextMate will
insert as many tabs as it estimates to be correct for that line. If the
line already has text the caret will move to the front of this text.
If the line already has the correct indent (or above) a single tab will be inserted.
4.10 Spell CheckingTextMate supports the system wide 'Check Spelling as You Type'. This can be changed in the Edit → Spelling submenu.
You can bring up the context sensitive menu for a misspelled word to get spelling suggestions.
Since TextMate is intended for structured text it is possible to
exclude parts of the document from being checked. This is done by
creating a preferences item in the bundle editor, setting
spellChecking to 0 and filling in the scope selector with the selector to target for no spell checking.By default spell checking is disabled for source code except strings
and comments and also for keywords, tags and similar in HTML, LaTeX,
Markdown, etc.
4.11 Using Spaces Instead of TabsTextMate can use spaces instead of tab characters. This is done by
clicking the “Tab Size” pop-up in the status bar and enabling Soft Tabs.
This setting will only affect the current language and all languages
with a common root that do not have the option set yet. The same
applies to the state of spell checking, soft wrap and the actual tab
size.
![]() When soft tabs are enabled, TextMate will for the most part act
exactly as if you were using hard tabs but the document does indeed
contain spaces.
5 BundlesA lot of functionality in TextMate is provided through various bundles, many of which are language specific.
The default bundles are located in
/path/to/TextMate.app/Contents/SharedSupport/Bundles.
Normally you do not need to care about this, as you inspect (and edit)
the bundles through the bundle editor (which can be reached through the
Window menu).5.1 Activation of Bundle ItemsIf you select Bundles → Bundle Editor → Show Bundle Editor you will see the command center for customizing TextMate.
![]() From this window you can create and edit things like snippets,
commands, language grammars, etc. which will be explained in more
detail in the following sections.
Most items edited in the Bundle Editor represent actions you want to
execute while editing text. TextMate offers a few ways to do this and
has a simple yet powerful system to understand the current context when
evaluating which action the activation method should result in, called scope selectors, which is explained in a later chapter.
5.1.1 Key EquivalentsThe easiest way to perform an action (from the keyboard) is in the
form of a key equivalent. A key equivalent can be any key with optional
modifiers and is configured by activating the key equivalent field and
pressing the key to which the item should be bound.
If you want to disassociate a key equivalent with an item, press the X shown while the key equivalent field is in recording mode.
If multiple items are given the same key equivalent then a menu will
appear when that key equivalent is pressed, as shown below (all of the
items in the Math bundle are bound to ⌃⇧C so a menu with each key
equivalent option is displayed).
![]() 5.1.2 Tab TriggersAs well as assigning a single key equivalent to a bundle item, it is possible to assign a tab trigger
to the item. This is a sequence of text that you enter in the document
and follow it by pressing the tab key (⇥). This will remove the
sequence entered and then execute the bundle item.
For example the Text bundle has a snippet which inserts the current
date conforming to ISO 8601 (YYYY-MM-DD). The tab trigger for this
snippet is
isoD (short for ISO Date). In your document it is thus possible to type isoD and press tab to “expand” that to the current date.This allows you to create much better mnemonics for your bundle
items as you can literally type the thing you want to execute (e.g. the
snippet to insert). It is generally a good idea to use actual words
instead of abbreviations (like use
list instead of lst)
since the purpose is to make it easier to remember, so the tab trigger
should generally be the first thing that pops into your mind in the
unabbreviated form.Tab triggers are rendered in the right side of the menu item with a
slightly rounded rectangle as background and the tab character (⇥)
shown as a suffix to the tab trigger.
![]() Tab triggers are also useful when they match program keywords and
lead to actions (such as inserting snippets) that do what you would
normally do after entering the keyword. For example in Ruby a method
starts with
def so creating a snippet for a Ruby method and assigning it def as tab trigger gives a natural flow, as you would write def as usual and then use tab instead of taking the normal actions. Had the tab trigger for a method (in Ruby) instead been method or similar, it means you would have to remember “I can insert a snippet for this” before typing def, whereas with def as the tab trigger, you have to remember it before pressing the space after def (basically just pressing tab instead of space).As with key equivalents, entering a tab trigger and pressing tab
will show a menu, when multiple items share the same tab trigger. This
can be used to provide a simple form of code-completion, for example in
CSS the tab trigger
list has been assigned to all properties that start with list. So in CSS typing list followed by tab will give a useful menu from where you can pick what list property needs to be inserted.![]() 5.2 Editing Default Bundles / ItemsSome of the default items may not be to your exact liking, for
example the coding style in snippets may differ from yours, so you may
want other tab triggers, key equivalents, or similar modifications.
If you edit a default item the difference will be stored in
~/Library/Application Support/TextMate/Bundles.
These are then merged with the default version so your changes will be
effective even after upgrading TextMate. All new items you create also
end up in this location.Bundles or bundle items which you install by dragging them to TextMate or double clicking will be installed in
~/Library/Application Support/TextMate/Pristine Copy/Bundles. Editing these will also result in only the differences being stored in ~/Library/Application Support/TextMate/Bundles,
meaning that if you later get a new version of this third party bundle,
you can safely install this one on top of the old one (by dragging it
to TextMate) and again your changes will be preserved.If you want to discard local changes then currently the only option is to delete these from
~/Library/Application Support/TextMate/Bundles.5.3 Deleting Default Bundles / ItemsYou can also transparently delete default bundles and bundle items
from the bundle editor. However, since the items are shipped with the
TextMate application, they are not removed on disk, since they would
then reappear after an upgrade.
Instead each bundle has an
info.plist file which keeps
the ordering of bundle items and also stores which of the default items
should act as if they have been deleted. When you change the ordering
of items in a default bundle or delete items, this file is copied to ~/Library/Application Support/TextMate/Bundles/«bundle name».tmbundle and will contain this info.If you delete an entire bundle the information is recorded in
TextMate’s preferences. You can get a list of which default bundles
have been deleted by running the following line in terminal:
To reset the list of deleted bundles (i.e. undelete them) instead run this (while TextMate is not running):
This may all sound a little complicated, but generally you should
not care about these details. Just use the bundle editor to create,
edit and delete your items and bundles and it should work as expected.
5.4 Hiding BundlesInstead of deleting default bundles you may want to just hide them
(since you never know if you someday will need some of the default
ones).
This is done by clicking the Filter List… button below the list in
the bundle editor. Here you can uncheck the bundles that you do not
wish to have shown in the various lists of bundle items.
![]() 5.5 Sharing Bundles and Bundle ItemsIf you want to share a bundle or particular bundle item then you can
drag it directly from the bundle editor (from the list in the left side
of the window) to the Finder.
This item can then be sent to other people and they will be able to
double-click it to install it. Note: this also works for single items,
like a snippet or a command.
5.6 Assorted BundlesOften a bundle will provide support for a particular language
(though there are exceptions like the Source, Text and TextMate
bundles). To get a good idea of what features the bundle provides, it
is best to investigate it in the bundle editor (accessible from the
Windows menu). When appropriate, a language bundle should provide the
following, with key bindings as shown:
Many bundles also have a Help command with some details about how to use and customize its functionality.
Bundle actions can be accessed through the gear pop-up in the status bar. This menu can also be brought up by pressing ⌃⎋.
Below are a few highlights from miscellaneous bundles.
5.6.1 DiffThe Diff bundle provides a language grammar for the output produced by the
diff shell command.You can show the differences between two files in TextMate by running the following command from your terminal:
The bundle also has commands to show the differences between the
current document and the saved copy, between the selected files in the
project drawer (with an HTML output option) and it has a command to
open the selected files in Apple's FileMerge using
opendiff (requires the developer tools to be installed).5.6.2 HTMLThe HTML bundle contains useful stuff for working with HTML. A few particularly useful actions are:
The HTML bundle also has a drag command for images which insert the
dropped image with proper dimensions (width/height) and an alternative
text derived from the file name.
A lot of actions in the HTML bundle will cause tags to be inserted. E.g. pressing ⌃↩ inserts
<br>, dropping an image on a HTML document inserts <img …>, etc.If you want tags with an EMPTY content model to use the minimized (XHTML) form (that is
<br /> instead of <br>) then in Preferences → Advanced create a new variable named TM_XHTML and set it to ‘ /’ (the value of this variable will be inserted before the > in the generated tags with EMPTY content model).For the records have a look at Sending XHTML as text/html Considered Harmful before embracing XHTML.
5.6.3 LaTeXThree commands of special interest in the LaTeX bundle are:
If you have not installed LaTeX you can use the i-installer (binaries).
Alternatively, if you have MacPorts then open your terminal and run:
5.6.4 SourceThe source bundle contains default actions and preferences for source code. Of interest is the Comment Line / Selection
(⌘/) which will toggle the comment characters for the current line or
selection. This command is setup for different languages via three context dependent variables.
The various macros to go to end-of-line and insert the line terminator character (
; by default) and/or a newline are also rather useful.5.6.5 SQLThe SQL bundle has a command that can submit the current line or
selection as a MySQL or Postgres query (⌃⇧Q) and show the result using
HTML output.
It uses a few environment variables to store connection details. These are described in the bundle’s Help file.
5.6.6 SubversionAll actions in the subversion bundle are accessible through ⌃⇧A.
These offer the commands which would be used in a common workflow.
None of the commands are made to prompt you for a password. For repositories offered through WebDav (i.e.
http or https) svn should cache your authentication. This post describes how to generate an ssh key pair for secure-shell tunneling (ssh).![]() The commit action will commit the files selected in the project
drawer or current file if there is no selection. The commit window also
allows you to exclude files before doing the actual commit.
In the commit window you can use enter (⌅) to trigger the “Commit” button shown in the bottom right corner.
5.6.7 TextThe text bundle is for actions and preferences related to basic text
editing. From a users perspective some of this should probably have a
more native placement than being in a bundle.
The four probably most useful actions are:
5.6.8 TextMateThe TextMate bundle is kind of a meta bundle. That means none of the
actions are for text editing but are instead intended for creating new
bundle items, searching the mailing list archive, pasting the current
selection to an IRC channel or similar.
![]() One command which is useful when working on themes or language grammars is the Show Scope (⌃⇧P) which shows the current scope of the caret (more about scopes later).
5.6.9 XcodeThe Xcode bundle has actions to build the Xcode project located in
the folder that contains the current document or project and to run the
resulting target.
![]() It also has commands to import an Xcode project but generally it is
better to drag the folder with your Xcode project to the TextMate
application icon, since currently the
TM_PROJECT_DIRECTORY variable is not correctly setup for imported projects and a lot of bundle actions rely on this (e.g. the Subversion stuff).5.7 Getting More BundlesOnly the most popular bundles are included with TextMate. There is a
subversion repository which has dozens of other bundles mostly adding
support for various languages. You can see the list of bundles here.
5.7.1 Installing SubversionIf you want to install one of these bundles you currently need to have the subversion client installed.
5.7.2 Setting
|


































