mac可以通过automator自制app, 实现在finder下双击.h, .cpp, .c等等你想用vim编辑的文件,直接打开item的vi窗口编辑该文件
applescript脚本挺好用啊。
本篇转载,原贴地址: http://thepugautomatic.com/2015/02/open-in-iterm-vim-from-finder/
When I double-click a code file in Finder, I want it to open in Vim in a terminal. Not in MacVim. Not in some lesser editor.
There’s plenty of prior work, but nothing worked well for me on OS X 10.10 Yosemite, so I rolled my own.
The end result: double-clicking a file opens a new iTerm window with the file opened in Vim.
Since it exec
s Vim (replaces the shell process), the window closes when you quit Vim. This also means you can’t ⌃Z
out of the Vim session. Think of it as an editor window, not a full-fledged terminal.
1. Get an .app
Download TerminalVim.app, unzip it and stick the app in /Applications
.
Or make your own:
- Open Apple’s “Automator” app.
- If you get a file dialog, opt to create a “New Document”.
- Select the “Application” type.
- Search the action list for “Run AppleScript”, double-click that option.
- Change the script to this (hat tip to Rob Peck):
- Save as
/Applications/TerminalVim.app
.
2. Tell Finder to use your app
- In Finder, select some file you want to open in Vim, e.g. a
.rb
file. - Hit
⌘I
to open the “Get Info” window. - Under “Open with:”, choose “TerminalVim.app”. You may need to select “Other…” and then browse.
- Hit the “Change All…” button and confirm.
Now all .rb
files in Finder will open in Vim.
3. Profit
That’s it!