升级 macOS 的 Vim

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

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

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

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

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

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

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

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

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

✗ brew info vim                             
vim: stable 8.0.1400 (bottled), HEAD
Vi 'workalike' with many additional features
https://vim.sourceforge.io/
Conflicts with:
  ex-vi (because vim and ex-vi both install bin/ex and bin/view)
/usr/local/Cellar/vim/8.0.1400_4 (1,423 files, 22.8MB) *
  Poured from bottle on 2018-01-09 at 22:49:45
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/vim.rb
==> Dependencies
Required: perl ✔, ruby ✔
Recommended: python ✔
Optional: gettext ✔, lua ✘, luajit ✘, python3 ✔
==> Options
--with-client-server
    Enable client/server mode
--with-gettext
    Build vim with National Language Support (translated messages, keymaps)
--with-lua
    Build vim with lua support
--with-luajit
    Build with luajit support
--with-override-system-vi
    Override system vi
--with-python3
    Build vim with python3 instead of python[2] support
--with-tcl
    Build vim with tcl support
--without-python
    Build vim without python support
--HEAD
    Install HEAD version
✗ 

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

✗ brew info vim                             
vim: stable 8.0.1400 (bottled), HEAD
Vi 'workalike' with many additional features
https://vim.sourceforge.io/
Conflicts with:
  ex-vi (because vim and ex-vi both install bin/ex and bin/view)
/usr/local/Cellar/vim/8.0.1400_4 (1,423 files, 22.8MB) *
  Poured from bottle on 2018-01-09 at 22:49:45
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/vim.rb
==> Dependencies
Required: perl ✔, ruby ✘
Recommended: python ✔
Optional: gettext ✔, lua ✘, luajit ✘, python3 ✔
==> Options
--with-client-server
    Enable client/server mode
--with-gettext
    Build vim with National Language Support (translated messages, keymaps)
--with-lua
    Build vim with lua support
--with-luajit
    Build with luajit support
--with-override-system-vi
    Override system vi
--with-python3
    Build vim with python3 instead of python[2] support
--with-tcl
    Build vim with tcl support
--without-python
    Build vim without python support
--HEAD
    Install HEAD version
✗

则运行 vim 会报错:

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

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

brew install ruby

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

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

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

最近更新: