Can I use
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
I want my
CTRL key to keep doing what it was designed to do.
CTRL-Cshould continue to send an
^ccharacter to my terminal to kill processes
CTRL-Vshould continue to send a
^vcharacter (the escape sequence in Vim)
CTRL-Xshould continue to send a
^xcharacter (vim’s key for “subtract
countfrom number under cursor)
I want to use the
CMD key to send commands to my window manager:
CMD-Cshould set the highlighted text/object to the X11
CMD-Vshould paste from the X11
CLIPBOARDbuffer -no matter what is in there– into the active target, like
CTL-Vor 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-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?
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-V are used. The only drawback so far is
CMD-V requires the user to release
V first to get the paste applied. So you cannot “hold repeat” it, neither can you release
CMD first (might trick your muscle memory at first).
First, create a script like this one:
#!/bin/bash active_window_id=$(xdotool getactivewindow) active_window_pid=$(xdotool getwindowpid "$active_window_id") process=$(cat /proc/$active_window_pid/comm) if [[ "$process" == "xterm" ]]; then xdotool key Control_L+Shift_L+v else xdotool key --clearmodifiers Control_L+v fi
Then, an example of valid config file for
"xsel -po|xsel -bi" Mod4+c "/path/to/your/script.sh" Release+Mod4+v
Example of valid config file for
super + c xsel -po|xsel -bi @super + v /path/to/your/script.sh
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.