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

@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