vim のヤンクでクリップボードにコピーしたかった話、あるいは vim 8 へのアップグレード (mac)
環境
OS | vim version |
---|---|
OSX 10.11.6 | 7.3 |
目的
mac の vim でヤンクしてクリップボードにいれたかった。
記事にしようと思ったきっかけ
よくある設定を .vimrc に書いてみましたが、有効にならず。
set clipboard=unnamed,autoselect
$ vim --version | grep clipboard -clientserver -clipboard +cmdline_compl +cmdline_hist +cmdline_info +comments -xterm_clipboard -xterm_save
記録しておこうと思いました。
ぐぐった
homebrew を update して、 vim をインストールしなおすのが手っ取り早いようでした。 http://djangoapplab.com/43/
homebrew の update
まず、sudo brew update してみたら怒られました。
Error: Running Homebrew as root is extremely dangerous and no longer supported. As Homebrew does not drop privileges on installation you would be giving all build scripts full access to your system.
そうなんですね。ごめんなさい。
なので一般ユーザで update してみます。
$ brew update Error: /usr/local is not writable. You should change the ownership and permissions of /usr/local back to your user account: sudo chown -R $(whoami) /usr/local
そうなんですね。
では、と chown して update すると進みはじめ、どかどか色々とインストールされていきます。
$ brew update ==> Homebrew has enabled anonymous aggregate user behaviour analytics. Read the analytics documentation (and how to opt-out) here: http://docs.brew.sh/Analytics.html Updated 3 taps (caskroom/cask, homebrew/binary, homebrew/core). ==> Cleaning up /Library/Caches/Homebrew... Removing: /Library/Caches/Homebrew/gcc-5.3.0.tar.bz2... (91M) Removing: /Library/Caches/Homebrew/gmp-6.1.0.el_capitan.bottle.tar.gz... (1M) Removing: /Library/Caches/Homebrew/isl-0.15.el_capitan.bottle.tar.gz... (1.2M) Removing: /Library/Caches/Homebrew/mpfr-3.1.3.el_capitan.bottle.tar.gz... (862.5K) Removing: /Library/Caches/Homebrew/openssl-1.0.2g.el_capitan.bottle.tar.gz... (3.6M) Removing: /Library/Caches/Homebrew/packer-0.10.0_1.el_capitan.bottle.tar.gz... (8.4M) Removing: /Library/Caches/Homebrew/pkg-config-0.29.1.el_capitan.bottle.tar.gz... (235.8K) Removing: /Library/Caches/Homebrew/ruby-build-20160330.tar.gz... (43.7K) Removing: /Library/Caches/Homebrew/sshrc-0.5.tar.gz... (3.4K) Removing: /Library/Caches/Homebrew/terraform-0.6.14.el_capitan.bottle.tar.gz.incomplete... (94.2M) Removing: /Library/Caches/Homebrew/tig-2.1.1.el_capitan.bottle.2.tar.gz... (154.4K) ==> Migrating /Library/Caches/Homebrew to /Users/rriifftt/Library/Caches/Homebrew... ==> Deleting /Library/Caches/Homebrew... 中略
/Library/
からホームディレクトリにマイグレーションしています。とても親切です。
さらに Formulae も新しくなっているようでした。
==> Migrating d-bus to dbus ==> Unlinking d-bus Moving to: /usr/local/Cellar/dbus ==> Linking dbus Error: Could not link: /usr/local/share/doc/homebrew Please delete these paths and run `brew update`. ==> Migrating HOMEBREW_REPOSITORY (please wait)... Error: Could not link: /usr/local/share/doc/homebrew Please delete these paths and run `brew update`. ==> Migrated HOMEBREW_REPOSITORY to /usr/local/Homebrew! Homebrew no longer needs to have ownership of /usr/local. If you wish you can return /usr/local to its default ownership with: sudo chown root:wheel /usr/local
最後には ↑ のログが出力されました。
ご案内の通りにします。
$ rm -rf /usr/local/share/doc/homebrew $ brew update Already up-to-date.
成功しました。
さらにご案内の通り /usr/local の権限を元に戻しておきます。
$ sudo chown root:wheel /usr/local
vim のインストール
vim は upgrade すればいいでしょと思ってやってみるとインストールされていないって言われました。
$ brew upgrade vim Error: vim not installed
clipboard が有効にならないのはこれが原因っぽいような。
ないなら install します。
$ brew install vim ==> Installing dependencies for vim: perl, readline, libyaml, openssl, ruby, pkg-config, sqlite, gdbm, python ==> Installing vim dependency: perl ==> Downloading https://homebrew.bintray.com/bottles/perl-5.24.0_1.el_capitan.bottle.1.tar.gz ######################################################################## 100.0% ==> Pouring perl-5.24.0_1.el_capitan.bottle.1.tar.gz 略 ==> Pouring vim-8.0.0329.el_capitan.bottle.tar.gz 🍺 /usr/local/Cellar/vim/8.0.0329: 1,713 files, 23.3M
vim 8 が降ってきました。
バイナリの切替
clipboard が有効になっているか確認してみると、変わっていません。
$ vim --version | grep clipboard -clientserver -clipboard +cmdline_compl +cmdline_hist +cmdline_info +comments -xterm_clipboard -xterm_save
vim インストール時のログを見ると別の場所にインストールされたようです。
こちらのバイナリで確認してみると有効になっています。
$ /usr/local/Cellar/vim/8.0.0329/bin/vim --version | grep clipboard +clipboard +job +path_extra +user_commands +eval +mouse_dec +statusline -xterm_clipboard
入れ替える必要がありそうなので入れ替えてみます。
$ mv /usr/local/bin/vim{,.bk} $ ln -s /usr/local/Cellar/vim/8.0.0329/bin/vim /usr/local/bin/vim
vim を起動する
と、エラーが出ました。
$ vim Command terminated Error detected while processing /Users/rriifftt/.vim/bundle/open-browser.vim/plugin/openbrowser.vim: line 19: E484: Can't open file /var/folders/g5/hsvhp9155l1c6sdc01rgqd4jwp37f2/T/v7qsLTu/0 Press ENTER or type command to continue
さらに iTerm で新しいタブを開くとローカルホストにログインできなくなりました。
Last login: Tue Feb 14 11:15:10 on ttys019 dyld: Library not loaded: /usr/local/opt/readline/lib/libreadline.6.dylib Referenced from: /usr/local/bin/bash Reason: image not found
やさしい人に readline を切り替えるとよくなるかもしれないと教えてもらいました。
確かに brew update した時に readline が更新されています。
==> Pouring readline-7.0.1.el_capitan.bottle.tar.gz ==> Caveats This formula is keg-only, which means it was not symlinked into /usr/local. macOS provides the BSD libedit library, which shadows libreadline. In order to prevent conflicts when programs look for libreadline we are defaulting this GNU Readline installation to keg-only. For compilers to find this software you may need to set: LDFLAGS: -L/usr/local/opt/readline/lib CPPFLAGS: -I/usr/local/opt/readline/include ==> Summary 🍺 /usr/local/Cellar/readline/7.0.1: 46 files, 2M ==> Installing vim dependency: libyaml ==> Downloading https://homebrew.bintray.com/bottles/libyaml-0.1.7.el_capitan.bottle.tar.gz
readline の切替
readline を切り替えてみます。
$ brew switch readline 7.0 Error: readline does not have a version "7.0" in the Cellar. Versions available: 6.3.6, 6.3.8, 7.0.1
コマンドエラーになってしまいましたが、3 つのバージョンがあることがわかりました。
そして現在のバージョンは以下です。
$ brew list readline /usr/local/Cellar/readline/7.0.1/include/readline/ (8 files) /usr/local/Cellar/readline/7.0.1/lib/libhistory.7.0.dylib /usr/local/Cellar/readline/7.0.1/lib/libreadline.7.0.dylib /usr/local/Cellar/readline/7.0.1/lib/ (6 other files) /usr/local/Cellar/readline/7.0.1/share/doc/ (3 files) /usr/local/Cellar/readline/7.0.1/share/info/ (3 files) /usr/local/Cellar/readline/7.0.1/share/man/ (2 files) /usr/local/Cellar/readline/7.0.1/share/readline/ (15 files)
最新版は色々とアレなんでしょうか。
6.3.8 に切り替えてみます。
$ brew switch readline 6.3.8 Cleaning /usr/local/Cellar/readline/6.3.6 Cleaning /usr/local/Cellar/readline/6.3.8 Cleaning /usr/local/Cellar/readline/7.0.1 Opt link created for /usr/local/Cellar/readline/6.3.8
再度 vim を起動する
と、エラーなく起動できました。
iTerm の新規タブも問題なく開くことができています。
いまのところはこれで問題なさそうです。