The last time I’m going to refer to it as the Windows key is in the title and in this sentence. We’ll go by it’s rightful name, the Super key. To make mine extra super, I cover the Windows logo with a Linux Penguin logo. I got this one from ThinkPenguin.com:

After using a Mac for about a year, I started to really like the approach of using the Command key for clipboard operations. Mostly because I still use the command line very often and I want to continue using Control+C for cancel. It’s like having your cake and eating it too. Why not put the Super key to use on my Ubuntu system for the same purpose?

We’ll cover the setup on several different applications. I like to add Cut, Copy, Paste at a minimum as well as Select All and Undo (since the A and Z keys are also in the vicinity). In cases where it’s possible, I’ve also mapped Redo as Shift+Super+Z since some programs would use Shift+Control+Z for Redo.

Programs

I’m not going to cover all of the applications that I use, just a few to get you started 🙂 What I like about my approach is in most cases I’m not overriding Control+A/Z/X/C/V. We’re augmenting it by adding Super+A/Z/X/C/V so using the control key will still work.

Here’s what we’re going to cover:

  • Gnome (mostly to remove other Super bindings)
  • GTK
  • Gnome Terminal
  • VSCode
  • Emacs
  • Nautilus (Gnome’s File Manager)

Gnome

We need to “free up” some of the default Gnome keybindings found in Ubuntu 18.04. Bring up the system Settings and navigate to Devices -> Keyboard. Type “super” there to filter all of the shortcuts to just those that use the Super key.

I simply changed Super+A and Super+V to Shift+Super+A and Shift+Super+V. You can see the customized shortcuts highlighted in bold.

Install Gnome Tweaks:

sudo apt install gnome-tweaks

After it’s installed launch Tweaks and navigate to the Keyboard & Mouse section.

Move “Overview Shortcut” from left super to right super, effectively disabling the overview on most laptops since they don’t have a right-side Super key. You can still access this functionality by pressing Super-S. Apologies to anyone that has a right-side Super key 😢

GTK

GTK keybindings will cover many applications – this setting alone might get you about 80% there. It will work on Firefox and Chrome – plus Electron apps based on Chrome like Simplenote and VSCode. Not all bindings will work in all apps (like Select-All, Undo & Redo) but Super-X/C/V should. Plus we’re augmenting the existing Control-A/Z/X/C/V so those will continue to work.

vi ~/.config/gtk-3.0/gtk.css

@binding-set gtk-super-cut-copy-paste
{
        bind "x" { "cut-clipboard" () };
        bind "c" { "copy-clipboard" () };
        bind "v" { "paste-clipboard" () };
        bind "a" { "select-all" (1) };
        bind "z" { "undo" () };
}

* {
        -gtk-key-bindings: gtk-super-cut-copy-paste
}

Details: https://askubuntu.com/a/851055/803610

Gnome Terminal

In 18.04 you can just go to Edit -> Preferences and set Copy, Paste and Select All in the Shortcuts section:

VSCode

Rather than using the keybinding editor in VSCode, I like to just open up the user keybindings.json file and add my keybindings as additions.

vi ~/.config/Code/User/keybindings.json

Super-X/C/V is already working from the GTK settings, so we just need to add the following to get Super-A/Z for Select-All/Undo/Redo:

// Place your key bindings in this file to overwrite the defaults
[
    {
        "key": "meta+a",
        "command": "editor.action.selectAll", "when": "textInputFocus"
    },
    {
        "key": "meta+z",
        "command": "undo", "when": "textInputFocus && !editorReadOnly"
    },
    {
        "key": "shift+meta+z",
        "command": "redo", "when": "textInputFocus && !editorReadOnly"
    }
]

Emacs

vi ~/.emacs

Yes I realize the irony of editing my .emacs file with vim.

Add the following lines:

;; Mac-style cut/copy/paste
(global-set-key (kbd "s-x") 'kill-region)
(global-set-key (kbd "s-c") 'kill-ring-save)
(global-set-key (kbd "s-v") 'yank)
(global-set-key (kbd "s-a") 'mark-whole-buffer)
(global-set-key (kbd "s-z") 'undo)

Nautilus (File Manager)

I adapted a program called BackspaceBack.py to do my bidding within Nautilus.

sudo apt install python-nautilus
mkdir -p ~/.local/share/nautilus-python/extensions
vi ~/.local/share/nautilus-python/extensions/KeybindingRemap.py

You’ll have to restart nautilus for these to take effect. Just log out and log back in to put the settings into action.

Looking Ahead

The way to do this has changed over the years from one major release to the next, so I won’t be surprised if some configurations are different for Ubuntu 20.04 LTS, but we’ll just have to wait and see. If you have any additional apps and configurations you’d like to add, let everyone know in the comments!

One thought on “Windows-X/C/V Cut/Copy/Paste in Ubuntu

  1. Pingback: XPS 13 Developer Edition Settings - Justin Foell

Leave a Reply