由于 macOS Mojave 下 MacVim 出现的问题 (Core Text rendering issues with macOS 10.14 Mojave · Issue #751 · macvim-dev/macvim · GitHub)至今没有修复好。我不得不考虑直接用 vim 来作为日常的编辑器了。
但是有两个小问题
- 不能复制到系统剪贴板;
- 不能对 Finder 中的文件,右键选择用 vim 打开;
对于第一个问题,只是因为系统自带的 vim 没有使用 -clipboard
参数编译的原因。所以我只要用 homebrew 重新安装 vim 就可以解决。
第二个问题有点麻烦,还好我搜索到原来使用 mac 系统中强大的自动化脚本 automator 就可以实现。具体的做法是
- 在 automator 中创建一个应用;
- 使用以下 applescript (由于我不懂 AppleScript,以下代码只是从网络上复制来的) . 他的原理其实就是创建 iTerm 窗口。然后执行
vim filename
打开文件。
on run {input, parameters}
set filename to POSIX path of input
set cmd to "clear;vim " & quote & filename & quote
tell application "iTerm"
create window with default profile
set bounds of front window to {300, 30, 1000, 1000}
tell the current window
tell the current session
write text cmd
end tell
end tell
end tell
end run
- 保存这个应用并放到应用目录下。然后就可以在 Finder 中,现在文件,右键选择用我们的应用程序打开了。
Automator 和 AppleScript 真是一个非常方便的自动化工具,而且已经支持使用 Javascript 来写脚本。