Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

MacOS10.9 + Vim7.4 + tmux で clipboard を共有する

Last updated at Posted at 2014-08-06

#概要
MacOS10.9 の Vim7.3 から homebrew でインストールした Vim7.4 へ切り替えたのが事の始まり。
clipboard を OS と Vim で共有にしたいと思い実践。こちらはうまくいくも次は tmux を立ち上げてから tmux 上での Vim では Clipboard が共有されないことが発覚。
全て解決したので備忘録を残します。

#手順

Vim7.4 インストール

  • インストールしましょう
$ brew update
$ brew install vim
$ brew list vim
/usr/local/Cellar/vim/7.4.335/bin/ex
/usr/local/Cellar/vim/7.4.335/bin/rview
/usr/local/Cellar/vim/7.4.335/bin/rvim
/usr/local/Cellar/vim/7.4.335/bin/view
/usr/local/Cellar/vim/7.4.335/bin/vim
/usr/local/Cellar/vim/7.4.335/bin/vimdiff
/usr/local/Cellar/vim/7.4.335/bin/vimtutor
/usr/local/Cellar/vim/7.4.335/bin/xxd
/usr/local/Cellar/vim/7.4.335/share/man/ (113 files)
/usr/local/Cellar/vim/7.4.335/share/vim/ (1503 files)
  • Vim7.3 から Vim7.4 へ切り替えます
  • clipboard が反映されていることも確認します
$ sudo mv /usr/bin/vim /usr/bin/old_vim                                                                                                                                           
$ sudo ln /usr/local/Cellar/vim/7.4.335/bin/vim /usr/bin/
$ vim --version | grep clipboard
+clipboard       +iconv           +path_extra      -toolbar
+eval            +mouse_dec       +startuptime     -xterm_clipboard
  • .vimrc に下記を追記して clipboard を共有できるようにします
.vimrc
set clipboard+=unnamed
  • backspace が使えないという事象が発生したので下記も追加します
.vimrc
set backspace=indent,eol,start

tmux + Vim7.4 で clipboard を共有可能にする

  • brew で reattach-to-user-namespace をインストールします
$ brew install reattach-to-user-namespace
  • .tmux.conf に下記を追記します
.tmux.conf
# キーバインドを vim 風に
set-window-option -g mode-keys vi

# コピーモードに入った際に v で選択開始, y もしくは enter で選択範囲をコピー
unbind -t vi-copy Enter
bind-key -t vi-copy v begin-selection
bind-key -t vi-copy y copy-pipe "reattach-to-user-namespace pbcopy"
bind-key -t vi-copy Enter copy-pipe "reattach-to-user-namespace pbcopy"
set-option -g default-command "reattach-to-user-namespace -l bash:"

環境によっては、[exited] が出力され tmux が起動できないことがあるようです。その場合には、set-option -g default-command "reattach-to-user-namespace -l bash: の行を削除し

.tmux.conf
set-option -g default-command ""

を設定することで回避できました。こちらでも tmux 上で vim を立ち上げた際に clipboard が共有されることが確認できました。

  • 最後に確実に反映するために tmux kill-server をします
$ tmux kill-server

以上で、tmux 上で Vim を立ち上げても clipboard が共有されるようになりました。

6
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?