24

Is it possible to backup the custom keyboard shortcuts and restore them when doing a fresh install?

5
  • 1
    I also have the same question. I took the privilege to rephrase your question.
    – user10853
    Commented Nov 2, 2016 at 14:00
  • 1
    Those are likely stored in .dconf. You can export and import those through gsettings. It is best to save the "setting" of these as a command. See askubuntu.com/questions/597395/… for example; all you need to find is the one you edited ;)
    – Rinzwind
    Commented Nov 2, 2016 at 15:50
  • 1
    How did you configure your keyboard shortcuts? Through the systems settings application or are you using custom-crafted XKB hooks? Commented Nov 2, 2016 at 15:57
  • @DavidFoerster yes through the systems settings (in my case I'm using Ubuntu Gnome)
    – user10853
    Commented Nov 2, 2016 at 21:15
  • A relevant answer has a Perl script that exports & imports shortcuts. The script works but it didn't save my custom shortcuts.
    – user10853
    Commented Nov 5, 2016 at 22:17

1 Answer 1

25

Gnome-Control-Center (used by Unity and Gnome Shell) stores its key bindings in the per-user Dconf database directories /org/gnome/desktop/wm/keybindings/ and /org/gnome/settings-daemon/plugins/media-keys/ (source).

  • The easiest way to keep them across system re-installations is to keep the per-user configuration directories (~/.config or more specifically ~/.config/dconf/user for Dconf only). Most of the time it's not necessary or desirable to purge the per-user configuration files anyway.

  • If you can't or won't keep your old Dconf database you can use the dconf command to export (“dump”) parts of it into a file and import (“load”) it later. The relevant Dconf directories are

    • /org/gnome/desktop/wm/keybindings/ for pre-defined shortcuts and
    • /org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/ for custom, user-defined shortcuts.

    The following example saves the above Dconf directories to two files keybindings.dconf and custom-keybindings.dconf and then restores them from the same files:

    dconf dump '/org/gnome/desktop/wm/keybindings/' > keybindings.dconf
    dconf dump '/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/' > custom-keybindings.dconf
    
    dconf load '/org/gnome/desktop/wm/keybindings/' < keybindings.dconf
    dconf load '/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/' < custom-keybindings.dconf
    

If you find that you export your keybindings often, it might be convenient to script the required steps.

5
  • Thanks for the explanation. I moved the user file to user.bk and my custom shortcuts still work (needs a reboot because a new file was created & seems to restore my preferences?) Also for dconf that directory (/org) doesn't exist
    – user10853
    Commented Nov 5, 2016 at 21:52
  • Where did you get the idea that there's no /org/ directory in the Dconf database? Both Unity and Gnome wouldn't work very well without it. Commented Nov 5, 2016 at 21:57
  • Because I tried cding into it & your command saves an empty file
    – user10853
    Commented Nov 5, 2016 at 22:03
  • 2
    You can't “change the working directory” to be a Dconf database directory because they're not part of a file system. Instead they are key prefixes in a hierarchical key-value store. Yes, the Dconf database is stored as a file but its contents aren't files. Commented Nov 6, 2016 at 4:15
  • 3
    For custom bindings, the path is /org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/. I'm on Debian Buster running Gnome 3.30.2.
    – Sufian
    Commented Aug 27, 2019 at 3:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .