How to disable mouse support in terminal?
Solution 1
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
(like xfce-terminal
) or rxvt
-based ones).
In vim
specifically, mouse
is normally not enabled by default in terminals. So there's probably a set mouse=a
somewhere in you ~/.vimrc
or your OS-supplied system vimrc. You can always add:
set mouse=
to your ~/.vimrc
to disable it. Or:
if !has("gui_running")
set mouse=
endif
to avoid disabling it for the GUI versions of vim
.
Mouse support is (sort of) advertised in the terminfo
database with the kmous
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:
infocmp -1x | grep -v kmous= | TERMINFO=~/.terminfo tic -x -
export TERMINFO=~/.terminfo
For applications using ncurses
, it's enough to set the XM
user-defined capability (not documented in terminfo(5)
but mentioned in curs_caps(5)
and curs_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:
infocmp -1x |
sed '/kmous=/d;/XM=/d;$s/$/XM=,/' |
TERMINFO=~/.terminfo tic -x -
export TERMINFO=~/.terminfo
Solution 2
Add the following two lines at the end of /etc/vim/vimrc :
set mouse=
set ttymouse=
Solution 3
I’m using this patch:
--- a/src/vteseq.cc 2020-01-25 21:39:47.737317745 +0100
+++ b/src/vteseq.cc 2020-01-25 21:40:12.811424242 +0100
@@ -462,18 +462,7 @@
void
Terminal::update_mouse_protocol() noexcept
{
- if (m_modes_private.XTERM_MOUSE_ANY_EVENT())
- m_mouse_tracking_mode = MOUSE_TRACKING_ALL_MOTION_TRACKING;
- else if (m_modes_private.XTERM_MOUSE_BUTTON_EVENT())
- m_mouse_tracking_mode = MOUSE_TRACKING_CELL_MOTION_TRACKING;
- else if (m_modes_private.XTERM_MOUSE_VT220_HIGHLIGHT())
- m_mouse_tracking_mode = MOUSE_TRACKING_HILITE_TRACKING;
- else if (m_modes_private.XTERM_MOUSE_VT220())
- m_mouse_tracking_mode = MOUSE_TRACKING_SEND_XY_ON_BUTTON;
- else if (m_modes_private.XTERM_MOUSE_X10())
- m_mouse_tracking_mode = MOUSE_TRACKING_SEND_XY_ON_CLICK;
- else
- m_mouse_tracking_mode = MOUSE_TRACKING_NONE;
+ m_mouse_tracking_mode = MOUSE_TRACKING_NONE;
m_mouse_smooth_scroll_delta = 0.0;
vte doesn’t care about my mouse anymore, so vim isn’t aware that I have one.
Related videos on Youtube
Ivan Voras
Updated on September 18, 2022Comments
-
Ivan Voras over 1 year
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.
-
goldilocks about 9 yearsNot an answer, but you should be able to use xfce4-terminal's own copy/paste from/to vim (shift-ctrl-c, shift-ctrl-v).
-
Stéphane Chazelas about 9 yearsYou know you can hold Shift to get the normal selection right?
-
Ivan Voras about 9 years@StéphaneChazelas if you add this as an Answer and not a Comment, I'll accept it :) I didn't know about the Shift! @ goldilocks: yes, I knew about shift-ctrl-c, it's not directly related to what I wanted.
-
-
Tobia over 5 yearsAre you sure about the terminfo solution? I just tried it on URxvt (with TERM=xterm-256color) but Aptitude is still responding to mouse clicks, which is super annoying. I wished URxvt had an option to disable mouse reporting entirely. I never use it and gets in the way more often than not.
-
Stéphane Chazelas over 5 years@Tobia, see edit.
-
Marius over 5 yearsThe manual page gives the information (and has, since August 2001).
-
Stéphane Chazelas over 5 yearsThanks @ThomasDickey, looks like I also messed up my test cases. See edit.
-
Marius over 5 yearsIf you use the
-1
option of infocmp (single column), the sed expression could be simplified. -
Stéphane Chazelas over 5 years@ThomasDickey, thanks. I thought it wasn't portable, while it seems it actually is and
-x
is not. I take it on systems where terminfo (tic) doesn't support user-defined capabilities (-x), the only option it to use a terminfo entry withoutxterm
in the name and description? -
Marius over 5 yearsOffhand, on those systems, the curses library doesn't know about the xterm mouse protocol that we're talking about (so the terminfo would be irrelevant).
-
Stéphane Chazelas over 5 years@ThomasDickey, but what about applications using ncurses on systems that have a terminfo (and curses) without user-defined attributes. Or does ncurses always installs its own terminfo database which it uses in place of the system's one? I do remember installing ncurses on Solaris decades ago, but don't remember the details.
-
Marius over 5 yearsncurses can do either, and its extensions are invisible to the system's tic/infocmp.
-
Stéphane Chazelas over 5 years@ThomasDickey, OK. Do you mean that if I use
export TERMINFO=~/.terminfo; ncurses-tic -x file
with thatXM=
, applications using the system'scurses
will still be able to read the~/.terminfo/m/myterm
and just ignore thatXM
capability? -
Marius over 5 yearsyes (short). Solaris is simple. Some old systems need ncurses configure
--with-caps
. See this page. -
Scott - Слава Україні over 4 yearsCan you tell us where this patch comes from, and explain how to apply it and what it does? … … … … … Please do not respond in comments; edit your answer to make it clearer and more complete.
-
Admin almost 2 yearsThanks for the
shift
key trick; this just saved me when I was trying to copy/paste an error message from a curses program that had grabbed the mouse.