2
2

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 3 years have passed since last update.

tmuxでクリップボード連携していい感じにコピペする

Last updated at Posted at 2020-08-24

tmuxを使えるようになりたいけど、マウス操作やコピペ周りがbashと違っていて、どうしても敬遠してしまいがち。
この辺の操作感だけでも普段のターミナルと同じにして、恐怖心をなくしてガンガン使っていこう!

まずはクリップボード連携をするため、xselをインストール

sudo apt install xsel

あとは.tmux.confをこんな感じに書き換える。

.tmux.conf

# mouse
set -g mouse on

# vi copy (clipboard)
set-window-option -g mode-keys vi

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
bind-key -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "xsel -bi"
bind-key -T copy-mode-vi Enter send-keys -X copy-pipe-and-cancel "xsel -bi"

# Explicit `C-c` key fires copying the selection
unbind -T copy-mode MouseDragEnd1Pane
unbind -T copy-mode-vi MouseDragEnd1Pane
bind-key -T copy-mode C-c send-keys -X copy-pipe-and-cancel "xsel -bi"
bind-key -T copy-mode-vi C-c send-keys -X copy-pipe-and-cancel "xsel -bi"

#解説

・マウススクロールを有効にする

set -g mouse on

・viのキーバインドを使う

set-window-option -g mode-keys vi

・マウスアップ時に選択完了せず、選択状態を維持し、Ctrl-cでクリップボードにコピーする

unbind -T copy-mode MouseDragEnd1Pane
unbind -T copy-mode-vi MouseDragEnd1Pane
bind-key -T copy-mode C-c send-keys -X copy-pipe-and-cancel "xsel -bi"
bind-key -T copy-mode-vi C-c send-keys -X copy-pipe-and-cancel "xsel -bi"
2
2
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
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?