守望的麦子

升级 macOS 的 Vim

2018-1-10    大连    /mac/2018/01/10/brew-vim.html mac mac,

本文最近更新于 2018 年 1 月 13 日,大连

macOS 默认已经安装了 Vim,可执行程序是 /usr/bin/vim,当前的系统 Vim 版本有一个问题是不支持与系统剪贴板的集成,另外由于是系统集成版本,使用一段时间后往往会出现版本低于当前 Vim 最新版的情况。

1 ✗ /usr/bin/vim --version | grep clipboard
2 -clipboard       +job             +path_extra      +user_commands
3 +eval            -mouse_dec       +statusline      -xterm_clipboard

解决方法是使用 Homebrew 安装 Vim 并替换系统自带 Vim:

1 brew install vim --with-override-system-vi

安装完成后重启终端以更新环境变量,输入 vim 后会发现 Vim 的版本已经是最新版本了。

如果以后想更新 Vim 版本,直接输入 brew upgrade vim 便能快速升级了。

如果想添加 python3 的支持,在以上命令基础上加上 --with-python3 即可,更多说明可以参见 brew info vim 命令结果:

 1 ✗ brew info vim                             
 2 vim: stable 8.0.1400 (bottled), HEAD
 3 Vi 'workalike' with many additional features
 4 https://vim.sourceforge.io/
 5 Conflicts with:
 6   ex-vi (because vim and ex-vi both install bin/ex and bin/view)
 7 /usr/local/Cellar/vim/8.0.1400_4 (1,423 files, 22.8MB) *
 8   Poured from bottle on 2018-01-09 at 22:49:45
 9 From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/vim.rb
10 ==> Dependencies
11 Required: perl ✔, ruby ✔
12 Recommended: python ✔
13 Optional: gettext ✔, lua ✘, luajit ✘, python3 ✔
14 ==> Options
15 --with-client-server
16 	Enable client/server mode
17 --with-gettext
18 	Build vim with National Language Support (translated messages, keymaps)
19 --with-lua
20 	Build vim with lua support
21 --with-luajit
22 	Build with luajit support
23 --with-override-system-vi
24 	Override system vi
25 --with-python3
26 	Build vim with python3 instead of python[2] support
27 --with-tcl
28 	Build vim with tcl support
29 --without-python
30 	Build vim without python support
31 --HEAD
32 	Install HEAD version
33 

注意其中的 Required: perl ✔, ruby ✔,如果显示为 Required: perl ✔, ruby ✘

 1 ✗ brew info vim                             
 2 vim: stable 8.0.1400 (bottled), HEAD
 3 Vi 'workalike' with many additional features
 4 https://vim.sourceforge.io/
 5 Conflicts with:
 6   ex-vi (because vim and ex-vi both install bin/ex and bin/view)
 7 /usr/local/Cellar/vim/8.0.1400_4 (1,423 files, 22.8MB) *
 8   Poured from bottle on 2018-01-09 at 22:49:45
 9 From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/vim.rb
10 ==> Dependencies
11 Required: perl ✔, ruby ✘
12 Recommended: python ✔
13 Optional: gettext ✔, lua ✘, luajit ✘, python3 ✔
14 ==> Options
15 --with-client-server
16 	Enable client/server mode
17 --with-gettext
18 	Build vim with National Language Support (translated messages, keymaps)
19 --with-lua
20 	Build vim with lua support
21 --with-luajit
22 	Build with luajit support
23 --with-override-system-vi
24 	Override system vi
25 --with-python3
26 	Build vim with python3 instead of python[2] support
27 --with-tcl
28 	Build vim with tcl support
29 --without-python
30 	Build vim without python support
31 --HEAD
32 	Install HEAD version
33 

则运行 vim 会报错:

1 ✗ vim
2 dyld: Library not loaded: /usr/local/opt/ruby/lib/libruby.2.5.dylib
3   Referenced from: /usr/local/bin/vim
4   Reason: image not found
5 [1]    53425 abort      vim
6 

这时可以通过 Homebrew 安装 ruby 修复:

1 brew install ruby

关于 Homebrew 的介绍参考这篇文章:macOS 缺失的软件包管理器 —— Homebrew

Vim 的配置文件和插件管理可以参考这里:一个 Vim 用户的精神之旅

关于作者
麦子,80 后,现从事通信行业。安卓玩家一个人的书房朗读者。
MRJENGLISH
jsntn
jasonwtien
jasonwtien
更多…… /about.html

最近更新: