Changing the default text editor on macOS

I’ve been using the same computer for almost a decade, but recently upgraded my computer.
By default, macOS uses Apple’s TextEdit app for any text file, and it’s pretty bad. Years ago, on my old machine, I setup Sublime to be my default editor for everything, but couldn’t remember how I did.
I eventually stumbled onto a thread on StackExchange with a working solution. I wanted to document it here so I wouldn’t forget again next time.


This content originally appeared on Go Make Things and was authored by Go Make Things

I’ve been using the same computer for almost a decade, but recently upgraded my computer.

By default, macOS uses Apple’s TextEdit app for any text file, and it’s pretty bad. Years ago, on my old machine, I setup Sublime to be my default editor for everything, but couldn’t remember how I did.

I eventually stumbled onto a thread on StackExchange with a working solution. I wanted to document it here so I wouldn’t forget again next time.

Just a heads up: this requires using the command line.

In terminal, copy-and-paste the command from below that matches the text editor you want to use as your default. Then, press return to run it, and restart your machine.

# Sublime Text 3
defaults write com.apple.LaunchServices/com.apple.launchservices.secure LSHandlers -array-add '{LSHandlerContentType=public.plain-text;LSHandlerRoleAll=com.sublimetext.3;}'

# Sublime Text 4
defaults write com.apple.LaunchServices/com.apple.launchservices.secure LSHandlers -array-add '{LSHandlerContentType=public.plain-text;LSHandlerRoleAll=com.sublimetext.4;}'

# VS Code
defaults write com.apple.LaunchServices/com.apple.launchservices.secure LSHandlers -array-add '{LSHandlerContentType=public.plain-text;LSHandlerRoleAll=com.microsoft.VSCode;}'

A lot of places suggested right clicking the file, selecting “Get Info,” and changing the “Open With” setting for all files of that type.

I tried that at first, but its time consuming when you work with lots of different file types. And it doesn’t work at all for hidden files like .htaccess and .gitignore.

The command line trick works for all text files across the whole system, including hidden files, and I never have to think about it again.


This content originally appeared on Go Make Things and was authored by Go Make Things


Print Share Comment Cite Upload Translate Updates
APA

Go Make Things | Sciencx (2022-01-05T15:30:00+00:00) Changing the default text editor on macOS. Retrieved from https://www.scien.cx/2022/01/05/changing-the-default-text-editor-on-macos/

MLA
" » Changing the default text editor on macOS." Go Make Things | Sciencx - Wednesday January 5, 2022, https://www.scien.cx/2022/01/05/changing-the-default-text-editor-on-macos/
HARVARD
Go Make Things | Sciencx Wednesday January 5, 2022 » Changing the default text editor on macOS., viewed ,<https://www.scien.cx/2022/01/05/changing-the-default-text-editor-on-macos/>
VANCOUVER
Go Make Things | Sciencx - » Changing the default text editor on macOS. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/01/05/changing-the-default-text-editor-on-macos/
CHICAGO
" » Changing the default text editor on macOS." Go Make Things | Sciencx - Accessed . https://www.scien.cx/2022/01/05/changing-the-default-text-editor-on-macos/
IEEE
" » Changing the default text editor on macOS." Go Make Things | Sciencx [Online]. Available: https://www.scien.cx/2022/01/05/changing-the-default-text-editor-on-macos/. [Accessed: ]
rf:citation
» Changing the default text editor on macOS | Go Make Things | Sciencx | https://www.scien.cx/2022/01/05/changing-the-default-text-editor-on-macos/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.