'Open With' Vim from MacOS Finder
Published 2020-05-08
I use Vim on the command line for almost all my text editing. Occasionally I find myself browsing around in Finder and wishing I could right-click a file and open it in Vim on the terminal.
I found the following solution. First, follow the instructions here to create a “TerminalVim.app” application. At this point, we’re 90% of the way there. You should be able to right-click any file, click Open With, choose Other, and browse to your new TerminalVim.app.
However, that’s still more steps than we would like. In order to add TerminalVim to your Open With list:
- Right-click your new TerminalVim.app, and click Show Package Contents.
- Open Contents/Info.plist
- Find the line
<key>CFBundleTypeExtensions</key>
and add new array items for each file type you want to associate with your app, as shown:
<key>CFBundleTypeExtensions</key>
<array>
<string>html</string>
<string>plist</string>
<string>csv</string>
<string>txt</string>
</array>
- Run
/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -f /Applications/TerminalVim.app
- Run
killall Finder
- You should now be able to right-click one of your chosen file types and open it in Vim!