Skip to content

Instantly share code, notes, and snippets.

@sam0x17
Last active July 30, 2023 18:17
Show Gist options
  • Save sam0x17/f1d89df55778e4317d8974623a62e8c6 to your computer and use it in GitHub Desktop.
Save sam0x17/f1d89df55778e4317d8974623a62e8c6 to your computer and use it in GitHub Desktop.
disable middle-click paste in linux without disabling middle scroll

Disable middle-click paste in Linux

Install packages:

sudo apt-get install xbindkeys xsel xdotool

Create xbindkey configuration file:

# ~/.xbindkeysrc
"echo -n | xsel -n -i; pkill xbindkeys; xdotool click 2; xbindkeys"
b:2 + Release

Set xbindkeys to load on startup:

# ~/.bashrc
xbindkeys -p

Log out, log back in, and you should be all set. If you are impatient, simply run xbindkeys -p

@Kvothe-The-Bloodless
Copy link

Kvothe-The-Bloodless commented May 17, 2019

This does not work for me. (Ubuntu 18.04.1 LTS). Installation goes without errors. I created a file ~/.xbindkeysrc with the text

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

I than ran xbindkeys -p. But I still paste with the middle mouse button.

I checked that b:2 is indeed the middle mouse button for me with xev:
"ButtonRelease event, serial 37, synthetic NO, window 0x4a00001, root 0x240, subw 0x0, time 15972433, (105,113), root:(1029,535), state 0x200, button 2, same_screen YES"

Any ideas what could be wrong? How can I make this work?


Update: I removed the "+ Release" and now it seems to work.

@MostHated
Copy link

This makes the middle scroll unable to be held anymore? I have to click and let go, then it toggles on the scroll instead of being able to just hold, scroll, then release.

@uisuru
Copy link

uisuru commented Apr 2, 2021

Ubuntu 20.04
Working with Kvothe-The-Bloodless suggestion.
Just remove '+ Release' from last line

@lon9man
Copy link

lon9man commented Apr 7, 2021

@uisuru
can you check does the middle click close tabs in Chrome (open URL in new tab) after your manipulation with disabling?

thanks

@Joey-Pepperoni
Copy link

I've been looking for a way to do this for so long, and this is almost perfect; however it still has issues. The problem is it messes with the other functionality of middle click. Usually i would just ignore this as another "solution" that just disables the middle click entirely, but it doesn't. It seems to have a very slight chance that a middle click input will go through without pasting. I've been able to use the middle click after sever seconds to several minutes of spamming the middle click, but haven't gotten a single paste in similar amount of spam. I'm new to linux and don't have the requisite skills to troubleshoot this myself, but it's so close to finally fixing an issue that's been making me really consider switching back to Windows.
I'm running Linux Mint 20.2 Cinnamon.

@Joey-Pepperoni
Copy link

Never mind, I preemptively removed + Release after hearing it causing issues for Kvothe, but adding it back fixed it. So THANK YOU for providing the first working solution I've found after days of searching. I hope other people with this issue find this.

@Joey-Pepperoni
Copy link

Never mind it doesn't fucking work. Why is this so hard to remove. It thought linux was supposed to be customizable.

@sam0x17
Copy link
Author

sam0x17 commented Oct 7, 2021

A much better way (if you are using something gnome-based) is to just use gnome-tweaks to disable middle click paste directly

@Joey-Pepperoni
Copy link

Hey, so it actually does work. I don't no why it didn't work for a while, but after a resets it has been working fine through multiple reboots. So no problem, i don't know what the problem was, but it's gone now.

@Joey-Pepperoni
Copy link

Sorry to cuase an issue when there wasn't one. I probably just set up /.xbindkeyssrc wrong or something like that. But this solution DOSE work.

@sauliusGTO3000
Copy link

thank you! I wasted 15 minutes to operate out this leftover from the past, so I can use my other leftover from the past - the trackpoint to scroll my IDE without pasting snippets all over the place :)

@joacopaz
Copy link

joacopaz commented Nov 3, 2022

You absolute gigachad. Thank you

@Wolfyxon
Copy link

Wolfyxon commented Jan 3, 2023

This is awesome! I can still use my mouse (even the middle click and scroll) and there's no annoying pastes. However middle button click event is slower by like 0.5s and that's annoying

@Sledmine
Copy link

Sledmine commented Jun 5, 2023

Any luck on removing that weird delay?

@ajayyy
Copy link

ajayyy commented Jul 30, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment