Sunday, 30 June 2019

linux - Binding Super+C Super+V to Copy and Paste


For some time I've been interested in binding the Windows Key (Super_L) on my keyboard to Copy and Paste for no other reason but convenience and consistency between my desktop and my MacBook.


I thought that I was close after reading about xmodmap and executing the following:


$ # re-map Super_L to Mode_switch, the 3rd col in keymap table `xmodmap -pke`
$ xmodmap -e "keycode 133 = Mode_switch"

$ # map Mode_switch+c to copy
$ xmodmap -e "keycode 54 = c C XF86_Copy C"

$ # map Mode_switch+v to paste
$ xmodmap -e "keycode 55 = v V XF86_Paste V"

Unfortunately, XF86Copy and XF86Paste don't seem to work, at all. They are listed in /usr/include/X11/XF86keysym.h and xev shows that the key sequence is being interpreted by X as XF86Paste and XF86Copy, do these symbols actually work? Do they have to have application level support?



Answer




What about binding your left Windows/Logo/Super key to act as another Ctrl key?


You can achieve that with the following xmodmap commands:


remove mod4 = Super_L
keysym Super_L = Control_L
add Control = Control_L

Assuming you saved the above lines as super_as_ctrl.xmodmap you can test out the effect by executing


xmodmap super_as_ctrl.xmodmap

To make the change permanent (surviving re-login/reboot) rename the file to .Xmodmap in your home folder.


(The above was tested on Ubuntu 11.10 live system, but it should be the same for other Linux distributions)





Having bound Super to Ctrl you can now use Super-C to copy almost everywhere. The only common exception is your terminal program. However you can redefine the shortcuts there.


I found out that even gnome-terminal has this option by now (I did not have until I got used to Ctrl-Shift-C anyway). In case you use that one, go to Edit / Keyboard Shortcuts... in the menu and assign Ctrl-C to copy and Ctrl-V to paste. Should be similar for konsole etc.


And don't worry, you won't loose the ability to terminate a program using a shortcut. After rebinding the copy shortcut for the terminal, you can just use Ctrl-Shift-C like you used Ctrl-C before. The terminal does not distinguish here if Shift is pressed or not. And the shortcut is not caught anymore for the copy. Alternatively rebind the terminate to another shortcut, as MountainX suggests in his answer.





Concerning the key symbols for copy and paste: Apparently they have no effect. I tested it quickly by assigning the copy action to Shift-ScrollLock (it was unused and I wanted to test with a non modifier key):


xmodmap -e 'keycode 78 = Scroll_Lock XF86Copy Scroll_Lock'

Pressing it had no effect, neither with XF86AudioMute. However it did work when assigning the letter 'a'. So I guess there is a specific problem with these XF86 special key symbols.


No comments:

Post a Comment

How can I VLOOKUP in multiple Excel documents?

I am trying to VLOOKUP reference data with around 400 seperate Excel files. Is it possible to do this in a quick way rather than doing it m...