Set TextMate as the default text editor on Mac OS X


Question or issue on macOS:

How can I set TextMate as default text editor on Mac OS X?

I’ve tried it with

ln -s /Applications/ ~/bin/mate
export EDITOR='mate -w'

but that doesn’t work.

How to solve this problem?

Solution no. 1:

Just right (or control) click a file of the type you want to change and:

“Get Info” -> “Open with:” -> (Select TextMate) -> “Change All”

Solution no. 2:

The method through Finder is not practical. If you’re a developer, your files likely include .profile, .gitconfig, .bashrc, .bash_profile, .htdocs, etc.

The best way to do this is in Bash (for Sublime Text 3):

defaults write LSHandlers -array-add '{LSHandlerContentType=public.plain-text;LSHandlerRoleAll=com.sublimetext.3;}'

For other text editors, I assume you can replace ‘com.sublimetext.3’ with the proper string. You could probably Google for your text editor’s name + “LSHandlerContentType=public.plain-text” to figure out what your app’s string would be.

For me, this changed the defaults for both Finder, and

$ open ~/.bashrc

Solution no. 3:

Have you modified your shell PATH environment variable to include ~/bin? That directory is usually not included in PATH by default on OS X. It might be simpler to create the symlink in /usr/local/bin which is usually included in PATH. Try:

echo $PATH

Solution no. 4:

To change the default text editor across the board, use the aforementioned method (i.e., “Get Info” → “Open with:” → (editor of choice) → “Change All”) on .txt files. Then it will be used as the default editor for any text-based file that doesn’t yet have an application preference for its extension.

For instance, if you use the terminal, the command open -t will use your preferred text editor, which is whatever application is associated with .txt files. By default this is (you guessed it) TextEdit, unless you explicitly specify otherwise.

Solution no. 5:

This worked for me on OS X v10.11 (El Capitan):

defaults write LSHandlers -array-add \

Solution no. 6:

For TextMate 2:

defaults write LSHandlers -array-add '{LSHandlerContentType=public.plain-text;LSHandlerRoleAll=com.macromates.TextMate;}'

And you need to restart after that.

Hope this helps!