How to Change the Default App for .txt Files on Mac
Every time you double-click a .txt file, macOS opens it in the default app for that file type — which out of the box is TextEdit. If you'd rather have files open in VS Code, BBEdit, Zed, or anything else, changing the default takes about 30 seconds and you only have to do it once.
The fastest way: Get Info
Find any .txt file in Finder. Right-click it and choose Get Info, or select it and press ⌘I. In the Get Info window, look for the Open with: section — it shows the current default app and has a dropdown next to it.
Click the dropdown and choose the app you want. If it's not in the list, choose Other... to browse your Applications folder.
Once you've selected the app, click Change All... at the bottom of the section. macOS will ask if you're sure — confirm it. From now on, every .txt file on your Mac opens in that app by default.
Alternative: right-click → Open With → Always Open With
Right-click any .txt file. Hold the Option key while the context menu is open — "Open With" changes to "Always Open With." Hover over it, choose your app from the submenu. This does the same thing as the Get Info method but is slightly faster once you know the trick.
Changing it back
Same process. Get Info on any .txt file, pick TextEdit (or whatever you want) from the Open With dropdown, click Change All. Takes the same 30 seconds to reverse as it did to set.
What if my app isn't in the list?
Some apps don't register themselves as text file handlers. VS Code and Zed both appear in the list after you've installed them. If your preferred editor isn't showing up, try choosing Other... and navigating to it manually in the Applications folder. If it still doesn't appear, the app hasn't declared itself compatible with plain text files — in that case, you can still open files in it using drag-and-drop or File → Open from inside the app.
For Terminal users
You can set the default handler from Terminal using the duti command, installable via Homebrew. For VS Code:
brew install duti
duti -s com.microsoft.VSCode public.plain-text allReplace com.microsoft.VSCode with the bundle identifier of your preferred app. You can find an app's bundle ID with: osascript -e 'id of app "AppName"'.
Get Info → Open With → Change All is the standard way, and it works reliably on every version of macOS. The whole process takes less time to do than to read about.