Set MacVim as default text editor on macOS

November 28, 2022

To set MacVim as the default text editor for plain text files on a Mac run the following command in a terminal & restart the computer:

defaults write com.apple.LaunchServices/com.apple.launchservices.secure LSHandlers -array-add '{LSHandlerContentType=public.plain-text;LSHandlerRoleAll=org.vim.MacVim;}'

This command updates the file ~/Library/Preferences/com.apple.LaunchServices/com.apple.launchservices.secure.plist which stores the file association preferences.

If a different editor than MacVim is desired substitute the text "org.vim.MacVim" for the bundle identifier of the preferred editor. To find the bundle identifier value right click on your editor in the Applications/ folder, select Show Package Contents, open the file Contents/Info.plist with any text editor and look for the string CFBundleIdentifier. The value should be on the next line. Examples:

# MacVim
<key>CFBundleIdentifier</key>
<string>org.vim.MacVim</string>

# Sublime Text 4
<key>CFBundleIdentifier</key>
<string>com.sublimetext.4</string>

History & source