Continuing my TMUX series, this time we will add better mouse support to your TMUX. (I also works over SSH if your local machine has a mouse).
You will add following functionality to your mouse:
- Resize panels draging on borders
- Select active panel with left click
- Zoom panel with right click
- Create window with right click on status bar
- Drag and interchange panels
- Drag windows
- Close panels with mouse-wheel click
- Close windows on the status bar with mouse-whell click
The same as last time: edit the tmux.conf file, save it, and finally tell TMUX to reload it.
$ gedit ~/.tmux.conf $ tmux -f ~/.tmux.conf
Mouse configuration
################################################################################ ## MOUSE CONFIGURATION ## ################################################################################ ## ENABLE MOUSE setw -g mouse on ## Mouse scroll ## If already in copy mode send mouse event x3 ## else if program is capturing mouse, simulate mouse with up strokes ## else (in normal tmux) enter copy mode bind-key -n WheelUpPane \ if-shell -Ft= "#{?pane_in_mode,1,#{?mouse_button_flag}}" \ "send-keys -Mt=; send-keys -Mt=; send-keys -Mt=" \ "if-shell -Ft= '#{alternate_on}' \ 'send-keys -t= ^y ^y ^y' \ 'copy-mode -e -t='" bind-key -n WheelDownPane \ if-shell -Ft= "#{?pane_in_mode,1,#{?mouse_button_flag}}" \ "send-keys -Mt=; send-keys -Mt=; send-keys -Mt=" \ "send-keys -t= ^e ^e ^e" ## Create new window on right click on the status bar on any other window unbind-key -n MouseDown3Status bind-key -n MouseDown3Status new-window -a -t= ## Drag windows on the status bar bind-key -n MouseDrag1Status swap-window -t= ## Drag panes (interchange them) bind-key -n MouseDrag1Pane swap-pane -dt= ## Close pane with mouse wheel (when released) bind-key -n MouseUp2Pane kill-pane -t= ## Close window whith wheel (released) bind-key -n MouseUp2Status kill-window -t= ## Enable mouse with 'm' and disable with 'M' unbind m bind m \ set -g mouse on \;\ display 'Mouse: ON' unbind M bind M \ set -g mouse off \;\ display 'Mouse: OFF' ## ZOOM: toggle with right click on pane unbind-key -n MouseDown3Pane bind-key -n MouseDown3Pane resize-pane -Z -t=
Now, I really recommend also adding to your TMUX configuration a cool theme.
Watchout! I stumbled across an error when changing my configuration file for an older system (don't worry, this configuration works just fine for the current TMUX 2).
ReplyDeleteThe option "mouse on" is only supported by newer TMUX versions. It enables support for all mouse related function. If you however want mouse support on an older TMUX version, use the following options instead:
## TMUX configuration file: ~/.tmux.conf
## ENABLE MOUSE SUPPORT FOR OLDER VERSIONS
setw -g mode-mouse on
setw -g mouse-resize-pane on
setw -g mouse-select-pane on
setw -g mouse-select-window on
setw -g mouse-utf8 on