I don't like having the middle mouse button paste, because I often end up with uncompilable code in Eclipse. How can I turn this off (in all programs)? I'm running Fedora.

  • 5
    Middle-click to insert selection is fundamentally part of the way X11 works; see http://www.jwz.org/doc/x-cut-and-paste.html. – ephemient Nov 10 '11 at 22:44
  • 1
    @Gilles: In all programs. :) – derekhh Nov 10 '11 at 23:26
  • 4
    I've not seen any trivial way to do this without nuking the middle mouse button altogether or hacking X or screwing with the normal clipboard as well, so my suggested "solution" is just to learn to use the middle mouse button properly. It's incredibly convenient to be able to highlight a text URL anywhere and go to it by middle clicking in my (FF) browser window. – jw013 Nov 10 '11 at 23:51
  • 7
    @ephemient "Middle-click to insert selection is fundamentally part of the way X11 works" ... way back when we had Sun Optical Mouses that needed about 1 pound of pressure on the middle button to get signal. Today the middle button is on hair trigger and moreover used as a wheel, this "fundamental" has to go (as quite a lot of "fundamental" stuff in X btw.) – David Tonhofer Feb 15 '18 at 14:44
  • 8
    I feel like the ability to disable whatever you want is an even more fundamental aspect of Linux. – Wayne Bloss Apr 5 '19 at 16:29

This solution will work globally and preserve the middle mouse functionality.

Install xbindkeys xsel xdotool

Place this in ~/.xbindkeysrc

"echo -n | xsel -n -i; pkill xbindkeys; xdotool click 2; xbindkeys"
b:2 + Release

Reload xbindkeys -p

Run xbindkeys on startup, pkill xbindkeys to stop.

| improve this answer | |
  • 8
    Thank you!!! I can't believe the only working solution has been sitting at 0 votes for exactly 2 years. – Retr0id Apr 19 '18 at 18:58
  • 4
    Finally, a solution which worked for me on Ubuntu Mate 17.10. Thank you! – Dmitry Frank Aug 11 '18 at 12:53
  • 5
    @spiil I tried this solution and it achieves the effect you want. I middle-clicked in a text field and nothing happens, but middle-clicking on a link and middle-clicking to close a tab work in Chromium, Firefox, and Waterfox (the three browsers I tested). – user7214865 Jan 7 '19 at 21:53
  • 4
    Scrolling by click-and-hold middle button no longer works with this solution :/ – Marc.2377 Mar 10 '19 at 3:36
  • 2
    You're a legend. I used the middle button on my trackball for scrolling purposes, but the paste functionality made my life miserable. Now it's in full bright colors again, thanks! – redsPL Aug 9 '19 at 23:48

In Fedora 24 you can install gnome-tweak-tool using the following command:

$ sudo dnf install gnome-tweak-tool

Open gnome-tweak-tool and go to the "Keyboard and Mouse" tab and disable "Middle-click-Paste".

| improve this answer | |
  • 4
    This is also available in Ubuntu 16.04: sudo apt-get install gnome-tweak-tool – Johnatilley Feb 9 '17 at 22:55
  • 3
    This only affects a few programs such as gedit, gnome-terminal and a few others. See also comment at askubuntu.com/questions/4507/…. – Kvothe May 17 '19 at 12:32

Having the middle button paste is a unix user interface standard, like having the left button select or activate, and the right button do something else (such as extending, toggling, firing up a menu, …). You'll find it bound to pasting in most unix applications.

If your problem is that your mouse is overly sensitive when you put your finger on the wheel, I suggest getting a better mouse. There are plenty of cheap decent mice.

You can reassign mouse button 2 to a different number. Applications identify the left, middle and right mouse buttons as buttons 1, 2 and 3 respectively. Put this code in a script that's executed when your X session starts (how to do that depends on your desktop environment).

echo 'pointer = 1 6 3 4 5' | xmodmap -
| improve this answer | |
  • 1
    Does not work. pastebin.com/0DYYMDLS – balki Aug 18 '15 at 2:21
  • @balki Weird. It certainly works for me. So to find out why it doesn't work for you, ask a new question. Be sure to mention which version of X.org (or other X server) you have, which distribution you're running this on, and what input devices are connected. – Gilles 'SO- stop being evil' Aug 18 '15 at 6:47
  • 4
    I'm betting OP doesn't care if it is standard (I know I don't). Doesn't matter. Mouse button actions should be more easily customizable. – Marc.2377 Mar 10 '19 at 3:30
  • Good answer. In my case, a variant is need: echo 'pointer = 1 0' | xmodmap - – pasaba por aqui Mar 4 at 19:43
  • 1
    @jrh My favorite mouse has a thumb button. It also has a wheel that's good enough not to be pressed by accident, but I rarely press it, because I use the thumb button. I doubt they make it anymore: it must be about 20 years old. It's very asymmetric though, I don't know if a left-handed version exists, that does unfortunately limit choices a lot. – Gilles 'SO- stop being evil' Apr 6 at 19:17

Scrollwheel mice support a middle-button click event when pressing the scrollwheel. This is a great feature, but you may find it irritating. Fortunately it can be disabled.

First, you need to know the id of the mouse, like this:

$ xinput list | grep 'id='

which prints something like

⎡ Virtual core pointer                      id=2    [master pointer  (3)]
⎜ Virtual core XTEST pointer                id=4    [slave  pointer  (2)]
⎜ PixArt Dell MS116 USB Optical Mouse       id=12   [slave  pointer  (2)]
⎣ Virtual core keyboard                     id=3    [master keyboard (2)]
  Virtual core XTEST keyboard               id=5    [slave  keyboard (3)]
  Power Button                              id=6    [slave  keyboard (3)]
  Video Bus                                 id=7    [slave  keyboard (3)]
  Power Button                              id=8    [slave  keyboard (3)]
  Sleep Button                              id=9    [slave  keyboard (3)]
  Dell KB216 Wired Keyboard                 id=10   [slave  keyboard (3)]
  Dell KB216 Wired Keyboard                 id=11   [slave  keyboard (3)]
  Eee PC WMI hotkeys                        id=13   [slave  keyboard (3)]

My Dell Usb mouse has printed here for which id=12

so, I can view the my mouse button mapping like:

$ xinput get-button-map 12

which prints

1 2 3 4 5 6 7 8 9 10 11 12

here only the first three numbers have meaning for me. They represent the left, middle, and right mouse buttons.

I can turn the middle mouse button off by setting it to 0:

$ xinput set-button-map 12 1 0 3

Or I can turn the middle-mouse button into a left-mouse button by setting it to 1:

$ xinput set-button-map 12 1 1 3

ref. link https://wiki.ubuntu.com/X/Config/Input

it works for me ( kubuntu 18.04 LTS )

| improve this answer | |
  • Works perfectly for touchpad in Slackware 14.2 (KDE). – Firelord Apr 27 '19 at 10:11
  • This is a better than any of the above that start with "download XX". The only issue I had is that for xinput set-button-map 12 1 0 3 you set all the buttons (1 - 12 for in this exampe xinput set-button-map 12 1 0 3 4 5 6 7 8 9 10 11 12) – blindguy Aug 6 '19 at 0:34
  • Working lubuntu 19.10. – nobody Mar 14 at 10:01
  • Note that you can find which button is which by pressing it and holding it down (then deleting any pasted text) then (with it still held down), type xinput query-state 12 (or whatever xinput id your mouse is, if it isn't 12), you can then see that only that button is down and you can disable it. I'm pretty sure this will disable middle mouse button functionality everywhere, not just for pasting, but this is what I wanted, I never use the middle mouse button because it's too sensitive. This does not affect the mouse wheel, though. – jrh Apr 6 at 15:55

EDIT: I just found an issue with the solution I've posted: in some programs (gitk at least, not sure how common it is) this will prevent text selection from working. So try it, but if you have problems with selecting text in a program you use regularly, then the solution is to stop using this.

Install xsel, and then run the following shell script:

while true; do
    xsel -fin </dev/null

As long as this script is running (you can set it to run on login) the middle mouse button will not paste in any application. So technically it will still paste, but there will always be nothing to paste.

The way it works is it runs xsel and has it copy (-i) the contents of /dev/null, without forking to the background (-n), and to actually hold that empty string in the buffer instead of just clearing it and exiting (-f). Every time it exits, it will invoke xsel again with the same options. Since xsel will keep running until another program "relieves it of duty" by copying something else, it won't constantly create new processes, instead keeping a single process running precisely until it is needed again. (Unless you have multiple instances of the script running, but there's no need to do that.)

Also no, this won't interfere with regular copy/paste, because the middle-click paste uses a separate clipboard.

| improve this answer | |
  • 1
    Thank you! I Use KDE, and this solution is the ONLY one that works for me. – Aloso Oct 25 '19 at 21:53
  • @Aloso You're welcome, just keep in mind the caveat at the top. If you ever find yourself unable to select text in a program, then that's the most likely culprit. – flarn2006 Oct 26 '19 at 22:03
  • Yes, I noticed this issue in Firefox' "Save File" dialog. Now I only turn this script on, when I'm programming. – Aloso Oct 26 '19 at 23:56
  • @Aloso Okay then; glad it's still of use to you :) – flarn2006 Oct 27 '19 at 3:17

Here's what you can do if you want to keep middle click functional (for clicking to open links in new tabs for example) without it pasting things.

First install sxhkd and xsel.

Then configure ./.config/sxhkd/sxhkdrc like so

    echo -n | xsel -n -i
~control + c
    echo -n | xsel -n -i
~control + shift + c
    echo -n | xsel -n -i
~control + x
    echo -n | xsel -n -i

And that's basically it.

Now start sxhkd (or configure it to launch on startup). Now, middle mouse will no longer paste anything but will otherwise function like normal.

| improve this answer | |
  • This still lets you use middle mouse for scrolling. Good solution! For me the file was in ~/.config/sxhkd/sxhkdrc – Atnas Sep 10 '19 at 15:49

It's a common convention that many programs abide by. There is no global way to turn it off, you must do it on a program by program basis.

EDIT: (short of, as Gilles says, disabling mouse button 2. But some programs do have other uses for mouse button 2, so I would not recommend this.)

| improve this answer | |

This is my script. Your's might need tweaking

echo -----Now fixing your scroll button --- -hold onto pants
xinput --list|grep "Virtual core XTEST pointer"
echo ---------------------------------------------------------------------------------

xinput --list|grep "Virtual core XTEST pointer" |awk '{
        for(i=1; i<=NF; i++) {
                tmp=match($i, /id=[0-9]+/)
                if(tmp) {
                        print $i
}' $1 |  tr -d '[:alpha:]='

echo fixing $id:

xinput set-button-map $id  1 10 2 4 5 6 7 8 9 3

xinput get-button-map $id
echo ---------------------------------------------------------------------------------
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.