I'm asking this question while using xfce4-terminal, but I'm interested in a general solution: is there a way to stop a terminal emulator announcing mouse support in consoles? I need mouse-select and copy-paste much more frequent that I need mouse support in vim or wherever.
How to disable mouse support in terminal
mouseterminalterminal-emulatorxfce4-terminal
Related Solutions
Put this block of code in your ~/.tmux.conf
. This will enable mouse integration letting you copy from a pane with your mouse without having to zoom.
set -g mouse on
bind -n WheelUpPane if-shell -F -t = "#{mouse_any_flag}" "send-keys -M" "if -Ft= '#{pane_in_mode}' 'send-keys -M' 'select-pane -t=; copy-mode -e; send-keys -M'"
bind -n WheelDownPane select-pane -t= \; send-keys -M
bind -n C-WheelUpPane select-pane -t= \; copy-mode -e \; send-keys -M
bind -t vi-copy C-WheelUpPane halfpage-up
bind -t vi-copy C-WheelDownPane halfpage-down
bind -t emacs-copy C-WheelUpPane halfpage-up
bind -t emacs-copy C-WheelDownPane halfpage-down
# To copy, drag to highlight text in yellow, press Enter and then release mouse
# Use vim keybindings in copy mode
setw -g mode-keys vi
# Update default binding of `Enter` to also use copy-pipe
unbind -t vi-copy Enter
bind-key -t vi-copy Enter copy-pipe "pbcopy"
After that, restart your tmux session. Highlight some text with mouse, but don't let go the mouse. Now while the text is stil highlighted and mouse pressed, press return key. The highlighted text will disappear and will be copied to your clipboard. Now release the mouse.
Apart from this, there are also some cool things you can do with the mouse like scroll up and down, select the active pane, etc.
If you are using a newer version of tmux on macOS, try the following instead of the one above:
# macOS only
set -g mouse on
bind -n WheelUpPane if-shell -F -t = "#{mouse_any_flag}" "send-keys -M" "if -Ft= '#{pane_in_mode}' 'send-keys -M' 'select-pane -t=; copy-mode -e; send-keys -M'"
bind -n WheelDownPane select-pane -t= \; send-keys -M
bind -n C-WheelUpPane select-pane -t= \; copy-mode -e \; send-keys -M
bind -T copy-mode-vi C-WheelUpPane send-keys -X halfpage-up
bind -T copy-mode-vi C-WheelDownPane send-keys -X halfpage-down
bind -T copy-mode-emacs C-WheelUpPane send-keys -X halfpage-up
bind -T copy-mode-emacs C-WheelDownPane send-keys -X halfpage-down
# To copy, left click and drag to highlight text in yellow,
# once you release left click yellow text will disappear and will automatically be available in clibboard
# # Use vim keybindings in copy mode
setw -g mode-keys vi
# Update default binding of `Enter` to also use copy-pipe
unbind -T copy-mode-vi Enter
bind-key -T copy-mode-vi Enter send-keys -X copy-pipe-and-cancel "pbcopy"
bind-key -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-pipe-and-cancel "pbcopy"
If using iTerm on macOS, goto iTerm2 > Preferences > “General” tab, and in the “Selection” section, check “Applications in terminal may access clipboard”.
And if you are using Linux and a newer version of tmux, then
# Linux only
set -g mouse on
bind -n WheelUpPane if-shell -F -t = "#{mouse_any_flag}" "send-keys -M" "if -Ft= '#{pane_in_mode}' 'send-keys -M' 'select-pane -t=; copy-mode -e; send-keys -M'"
bind -n WheelDownPane select-pane -t= \; send-keys -M
bind -n C-WheelUpPane select-pane -t= \; copy-mode -e \; send-keys -M
bind -T copy-mode-vi C-WheelUpPane send-keys -X halfpage-up
bind -T copy-mode-vi C-WheelDownPane send-keys -X halfpage-down
bind -T copy-mode-emacs C-WheelUpPane send-keys -X halfpage-up
bind -T copy-mode-emacs C-WheelDownPane send-keys -X halfpage-down
# To copy, left click and drag to highlight text in yellow,
# once you release left click yellow text will disappear and will automatically be available in clibboard
# # Use vim keybindings in copy mode
setw -g mode-keys vi
# Update default binding of `Enter` to also use copy-pipe
unbind -T copy-mode-vi Enter
bind-key -T copy-mode-vi Enter send-keys -X copy-pipe-and-cancel "xclip -selection c"
bind-key -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-pipe-and-cancel "xclip -in -selection clipboard"
In Debian and Debian based distros (Ubuntu, Kali), you might need to install xclip
:
sudo apt-get install -y xclip
(You may also check out https://github.com/gpakosz/.tmux for many other tmux options.)
zsh
can be extended to support mouse operation like you describe, using Stéphane Chazelas’ mouse.zsh
ZLE widget:
wget http://stchaz.free.fr/mouse.zsh
. ./mouse.zsh
zle-toggle-mouse
(and once you’ve tested it, add it to your ~/.zshrc
).
It will work in any terminal with VT200 mouse tracking, and in the Linux console with gpm
.
Best Answer
You can hold the Shift key to use the normal mouse selection while xterm mouse-tracking is enabled. That works in all terminal emulators that I know (
xterm
,vte
(likexfce-terminal
) orrxvt
-based ones).In
vim
specifically,mouse
is normally not enabled by default in terminals. So there's probably aset mouse=a
somewhere in you~/.vimrc
or your OS-supplied system vimrc. You can always add:to your
~/.vimrc
to disable it. Or:to avoid disabling it for the GUI versions of
vim
.Mouse support is (sort of) advertised in the
terminfo
database with thekmous
capability. Now, not all applications rely on that to decide whether to enable mouse tracking or not.You could redefine the entry for your terminal (in a local terminfo database) to remove that capability:
For applications using
ncurses
, it's enough to set theXM
user-defined capability (not documented interminfo(5)
but mentioned incurs_caps(5)
andcurs_mouse(3)
) to the empty string. That doesn't prevent the application from handling mouse events if they're sent by the terminal, but that prevents the application from sending the sequence that enters the mouse tracking mode. So you can combine both with: