Disabling middle mouse paste Linux

The “middle mouse button paste” behavior on Linux desktops can lead to posting unwanted text in a document when simply trying to scroll through it. Disabling this behavior depends on whether Wayland or X11 is being used.

The middle mouse button paste behavior is typically managed by the compositor. Look for desktop environment settings related to mouse behavior or clipboard management to disable it.

  • GNOME: gsettings set org.gnome.desktop.interface gtk-enable-primary-paste false
  • KDE Plasma 6 (Wayland): System Settings → Workspace → General Behavior → uncheck Middle Click: Paste selected text and restart session.
  • XWayland / X11-only apps: XMousePasteBlock as a user service.

X11 desktop

Disable Linux middle-mouse button paste in Terminal:

xmodmap -pp

Telling the active mouse button function indices. The second number is apparently the middle mouse button function, which we will map to an unused index. Example output of xmodmap -pp:

There are 10 pointer buttons defined.
Physical Button      Button Code
1                    1
2                    2
3                    3
4                    4
5                    5
6                    6
7                    7
8                    8
9                    9
10                   10

Edit ~/.Xmodmap - swap the last number with the second number. Keep a backup of the ~/.Xmodmap file if one existed. For the example above, edit and save:

pointer = 1 10 3 4 5 6 7 8 9 2

Finally, logout / login

the middle-mouse paste should be disabled, while still able to use the middle mouse button to scroll.

Reference