If you are not aware, in Linux, you can use the mouse middle click to paste content into your text documents. Together with a clipboard manager, this can be a very useful feature that allows you to do things more efficiently, except that it can also be very annoying at times.
For those with a sensitive mouse, you will find that everytime you scroll your mouse wheel too fast (which translate into a middle click), it will paste the previous copied content to your text editor, documents or any other input text field, without your knowledge. For writers, developers or anyone working on a written project, this is very frustrating.
As this is a system level feature, there are no easy ways to disable the mouse middle click to paste feature, but there are some workarounds/hacks that we can use.
Remapping the mouse middle-click function
One of the hack is to remap the mouse middle click button to other commands, like left or right click. This will effectively kill the middle-click to paste feature. However, this will also disable all middle click functions, so you won’t be able to middle click a folder to open in new tab in Nautilus, open new links or close a open tab.
1. Open a text editor and add the following text:
pointer = 1 6 3 4 5 2
and save the file as “.Xmodmap” (without the quote) in your home folder.
Log out of your session and login again. Your mouse middle click will not be functional now.
Disable middle click to paste in Firefox
If you are mainly working in the Firefox browser, you can deactivate the middle click to paste feature without losing your mouse middle click functionality.
On the URL bar, type “about:config“, press Enter and click the “I’ll be careful, I promise” button.
select for “
middlemouse.paste“. Double click on it to change the value from “true” to “false”.
Disable middle click to paste in Chrome
Unlike Firefox, there is no configuration options to turn disable the middle-click to paste feature. However, you can install the Autoscroll extension to remap the middle mouse button to autoscroll instead.
For Hardcore users: Patching the gtk source file
This particular hack involves patching the gtk source file and is meant for those experienced Linux users who know what they are doing. You will need to install a whole bunch of files and compiler code.
The following instruction was adapted from Assembla and modified to work for Gtk 3.0.
Open a terminal and type the following:
sudo apt-get update sudo apt-get upgrade
Next, grab the necessary files for compiling the code:
sudo apt-get build-dep gtk+3.0 sudo apt-get install build-essential
Download the patch file
mkdir /tmp/gtk cd /tmp/gtk wget http://subversion.assembla.com/svn/slipstream/patches/gtk_disable_middle_mouse_button_paste.patch
Now, we are going to grab the gtk 3.0 source code
apt-get source libgtk-3-0 cd gtk+3.0-3.2.0
Apply the patch:
patch -p1 < /tmp/gtk/gtk_disable_middle_mouse_button_paste.patch
Recompile the source code:
sudo apt-get install cdbs sudo dpkg-buildpackage -uc -us
Install the patched file:
sudo dpkg -i ../libgtk-3-0_3.2.0-0ubuntu6_i386.deb
The code above is meant for gtk 3.2.0. If your gtk version is different, change the version number above.
That’s it. Log out and login again. The mouse middle-click to paste feature should be disabled now.
1. It is possible that any future update of the gtk code will override the changes. You might need to re-apply the patch again to disable the middle-click to paste.
2. This patch doesn’t disable the middle-click to paste feature in Firefox. You still need to manually disable it in the about:config (see above).
3. I have tried this on Ubuntu Oneiric and it worked. I have not tried it on Ubuntu Precise (12.04).
Using xsel to paste empty content
This is another hack by Marco Ceppi. Rather than disabling the mouse middle-click to paste feature, it uses “xsel” to paste empty content when the middle button is clicked.
Here is the hack. First, install xsel:
sudo apt-get install xsel
Download this hack file and place it in your home folder.
Make it executable (Right-click -> Properties -> Permissions -> Allow executing file as program).
Create a new entry in the startup applications and add the following:
Note: This script will run an endless loop to detect mouse middle click and empty the copied content.