LoginSignup
48
43

More than 5 years have passed since last update.

tmux 2.1 以降でもマウスを有効にする方法

Last updated at Posted at 2015-10-19

tmux/CHANGES@310f0a9 によると、

CHANGES FROM 2.0 to 2.1 18 October 2015

Incompatible Changes
====================

* Mouse-mode has been rewritten.  There's now no longer options for:
    - mouse-resize-pane
    - mouse-select-pane
    - mouse-select-window
    - mode-mouse

  Instead there is just one option:  'mouse' which turns on mouse support
  entirely.

とのことです。そういうわけで、.tmux.conf とかに

set-window-option -g mode-mouse on
set-option -g mouse-select-pane on
set-option -g mouse-resize-pane on
set-option -g mouse-select-window on

みたいに書いてあったであろう奴らが一切動かなくなっています。これを直すには、

.tmux.conf
set-option -g mouse on

bind -n WheelUpPane   select-pane -t= \; copy-mode -e \; send-keys -M
bind -n WheelDownPane select-pane -t= \;                 send-keys -M

というのをそのあたりに書けばオッケーです (下2行は https://bbs.archlinux.org/viewtopic.php?pid=1572476#p1572476 から引用)。

複数マシン間で .tmux.conf を共有していると、これらのうちどっちを書けばいいんやみたいな感じになりますが、両方書いておくと使えない方のエラーが起動時に毎回表示されるだけで動くことには動きます。

きちんとバージョンごとに動作を切り分けたい場合は、if-shell を使って

.tmux.conf
if-shell 'test $(echo "$(tmux -V | awk \{print\ \$2\}) > 2.0" | bc) -ne 0' \
  'source-file ~/.tmux.d/mouse-after-2.1.conf' \
  'source-file ~/.tmux.d/mouse-before-2.0.conf'
~/.tmux.d/mouse-after-2.1.conf
set -g mouse on
bind -n WheelUpPane   select-pane -t= \; copy-mode -e \; send-keys -M
bind -n WheelDownPane select-pane -t= \;                 send-keys -M
~/.tmux.d/mouse-before-2.0.conf
set-window-option -g mode-mouse on
set-option -g mouse-select-pane on
set -g mouse-resize-pane on
set -g mouse-select-window on

このようなことをやればよいです。if-shell で分岐した先で必ず source-file を使わないといけないわけではないですが、使わないと死ぬほど見難い感じになります、、

48
43
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
48
43