search
LoginSignup
0

More than 3 years have passed since last update.

posted at

updated at

viモードのtmuxでwin32yankとpbcopyを使う

一つのtmux.confファイルでWSL用ではwin32yank.exeを使うよう、Macではpbcopyを使うようにしたかったのでif-shellを使って環境ごとにクリップボード共有ツールを変えるようにしました。

tmux.confファイル全体はこちら
https://github.com/tMinamii/dotfiles/blob/master/tmux/tmux.conf

tmux.conf
setw -g mode-keys vi
unbind -T copy-mode-vi Enter
bind-key -T copy-mode-vi v     send-keys -X begin-selection
bind-key -T copy-mode-vi C-v   send-keys -X rectangle-toggle

## for WSL2
if-shell -b 'test "$(uname -a | grep microsoft)" != ""' \
  'bind-key -T copy-mode-vi Enter send-keys -X copy-pipe-and-cancel "cat | win32yank.exe -i"; \
   bind-key -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "cat | win32yank.exe -i"; \
   bind-key C-p run-shell "win32yank -o | tmux load-buffer - && tmux paste-buffer"'

## for Mac
if-shell -b 'test "$(uname -a | grep Darwin)" != ""' \
  'bind-key -T copy-mode-vi Enter send-keys -X copy-pipe-and-cancel "pbcopy"; \
   bind-key -T copy-mode-vi y     send-keys -X copy-pipe-and-cancel "pbcopy"; \
   bind-key C-p run-shell "pbpaste | tmux load-buffer - && tmux paste-buffer"'

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
What you can do with signing up
0