Can I use CMD-C
and CMD-V
to trigger the X11 clipboard functionality?
I do not want to remap CMD
to send CTRL
. This is not just about ergonomics and muscle memory. Existing answers seem to ignore the fact that ^C
is a valid, useful character with its own meaning to lots of programs. I want to bind window manager commands (like copy/paste) to key combinations that don't already have decades-old conventions associated with them in popular programs, like Vim and Emacs. Something like CMD-C
.
I want my CTRL
key to keep doing what it was designed to do.
CTRL-C
should continue to send an^c
character to my terminal to kill processesCTRL-V
should continue to send a^v
character (the escape sequence in Vim)CTRL-X
should continue to send a^x
character (vim's key for "subtractcount
from number under cursor)
I want to use the CMD
key to send commands to my window manager:
CMD-C
should set the highlighted text/object to the X11CLIPBOARD
selection.CMD-V
should paste from the X11CLIPBOARD
buffer -no matter what is in there– into the active target, likeCTL-V
or Edit->Paste does by default in almost every X application.
MacOS does system-wide shortcuts really well. It took some muscle memory adjustment, but now that I've realized that I can send actual control characters to my applications, I can't ever go back.
Can I configure my linux box to do the same thing, at least for copy & paste? The biggest sticking point is that CTRL-C
/CTRL-V
for copy/paste conflicts with vim keybindings, but generally I'd like to separate terminal control characters from window-manager command sequences.
There's a bit of useful documentation on Jamie Zawinski's site on the underlying mechanisms for how X11 handles copy/paste buffers. This is exactly the functionality I want to directly control with my keyboard. How do I configure it?
Best Answer
This is a hard problem because a lot of apps on Linux try to be smart about it and re-implement the logic on their side. Also because the concept of clipboard in X11 is broader and has several ones with different behaviors.
My setup consists of using a keybinding daemon and execute commands whenever
CMD-C
andCMD-V
are used. The only drawback so far isCMD-V
requires the user to releaseV
first to get the paste applied. So you cannot "hold repeat" it, neither can you releaseCMD
first (might trick your muscle memory at first).First, create a script like this one:
Then, an example of valid config file for
xbindkeys
:Example of valid config file for
sxhkd
:You can use your WM config to map the commands too, and map additional ones, like
CMD+A
for "select all",CMD+X
for cut, and so on.