てけもぐ Tech 忘備録

Shortcut with Super key for Copy/Paste on GNOME desktop like MacOS

対象読者

GNOME users

解決すること

Enable Super short(or Meta) short cut key for Copy/Paste action on GNOME desktop

内容

I moved from Mac to Ubuntu recently and tried to have shortcut keys similar with Mac's ones. Thank you for many web pages explaining them, but copy/paste was last challenging point for me.

Here are summarize from me(on Ubuntu 22.04 LTS)

  • gtk resource under ~/.config dir does not work for shortcut with Super key. These modifier keys other than shift/alt/control are filtered out in gtkimcontextsimple.c. The gtk4 has updated code, but looks more directly filtered out. gtk3 allows mod1,(usually alt key), gtk4 hard coded them.
  • I tried remapping Super key to mod1 from mod4 via xkb configuration, but I can not enable it on Wayland env.
  • gnome-terminal uses vte module instead gtktextview. The vte module implements own shortcut handler. As we can see terminal configuration panel, Super key can be used for copy and paste shortcuts.
  • Firefox is configurable to use Super key as hotkey.
  • Yes, VScode has own shortcut configuration and we can use Super for Copy/Paste

Initially I tried to find the way to enable copy/paste shortcut with Super key for all application on GNOME, but noticed I need only three applications... Terminal, Browser and IDE. So I finally got the way I wanted as bellow.

  1. Configure shortcuts using GNOME preference tool. In my case, disabled almost shortcuts using Super key.
  2. Configure Terminal shortcuts on it's preference window to use Super for copy/paste.
  3. Install gnome-tweaks via apt command and disable Super as window operation key (Also enable Emacs key bindings or so). We can find lots of pages explaining this.
  4. If Gnome dock or any other components still grab the super key, please use gsettings tool to disable them. I referred to https://www.reddit.com/r/gnome/comments/n7togl/how_to_disbale_super_key_number_keys_dock/
  5. Configure firefox to use Super key for the shortcut(hotkey on firefox). Open 'about:config' page and set "ui.key.accelKey" to 91. Thanks info to https://bugzilla.mozilla.org/show_bug.cgi?id=426891 .
  6. For IDE like VSCode, it's easily found on net how to configure shortcut.
  7. If some more key configuration on gtk with Control/Alt/Shift modifiers, resource file under ~/.config/{gtk-3.0,gtk-4.0}/gtk.css works to configure shortcuts. Emacs css file(/usr/share/themes/Emacs/gtk-3.0/gtk-keys.css) is used as sample reference.

Now Super+c for copy and Super+v for paste can be used on firefox, terminal and VSCode while control is available for separate modifier keys.