This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Where is the configuration file to store keyboard shortcuts?

Tags: shortcut, keyboard, hotkey, .khotkeys, khotkey-scheme, scheme shortcut, keyboard, hotkey, .khotkeys, khotkey-scheme, scheme shortcut, keyboard, hotkey, .khotkeys, khotkey-scheme, scheme
(comma "," separated)
hodd27
Registered Member
Posts
4
Karma
1
Where is/are the configuration file(s) that store(s) keyboard shortcuts of KDE products such as KDE Plasma 5, Konsole and KWrite?

I would like to back up my custom settings for keyboard shortcuts so that I can restore them in the future when further customizations of shortcuts mess things up.

Standard Shortcuts and Global Shortcuts can be customized on GUI by `System Settings > Workspace > Shortcuts`. Shortcuts specific to Konsole can be customized by `Konsole > Settings > Configure Shortcuts...`. Shortcuts specific to KWrite can be customized by `KWrite > Settings > Configure Shortcuts...`.

I do not see any export, save or load button on the GUI dialog window. (I am on Debian 9.3.) So, I am thinking about backing up the configuration file(s) directly. Where is/are the configuration file(s) that store keyboard shortcuts?

I looked into `~/.kde/share/config` and `/etc`, but could not find anything that seems to store keyboard shortcuts.

Recent KDE products may store the settings somewhere different from where old KDE used to store. I would like to know about KDE products that come with Debian 9. Debian 9.3 comes with Plasmashell 5.9.4, Konsole 16.12.0 and KWrite 16.08.3.
User avatar
TKL-Ansi
Registered Member
Posts
42
Karma
0
OS
I found shortcuts in the same folder that stores my customized toolbars.

~/.local/share/kxmlgui5


:wq
hodd27
Registered Member
Posts
4
Karma
1
I am going to write the following three things:
    - The locations of the preference files to store the keyboard shortcuts of KDE Plasma 5 and of some of its associated applications
    - How to find these preference files
    - How to back up and restore them

The following files store the keyboard shortcuts of KDE Plasma 5 and of some of its associated applications such as Konsole and KWrite.

    ~/.config/kdeglobals
    ~/.config/kglobalshortcutsrc
    ~/.config/khotkeysrc
    ~/.config/kwinrc
    ~/.config/plasma-org.kde.plasma.desktop-appletsrc
    ~/.local/share/kxmlgui5/katepart/katepart5ui.rc
    ~/.local/share/kxmlgui5/konsole/konsoleui.rc
    ~/.local/share/kxmlgui5/konsole/sessionui.rc
    ~/.local/share/kxmlgui5/kwrite/kwriteui.rc


Let me add descriptions for the files.

Standard Shortcuts (System Settings > Shortcuts)
~/.config/kdeglobals

Global Shortcuts (System Settings > Shortcuts)
~/.config/kglobalshortcutsrc

"Custom Shortcuts" (System Settings > Shortcuts)
~/.config/khotkeysrc

Konsole
~/.local/share/kxmlgui5/konsole/konsoleui.rc
~/.local/share/kxmlgui5/konsole/sessionui.rc

KWrite > Settings > Configure Shortcuts... > KWrite
~/.local/share/kxmlgui5/kwrite/kwriteui.rc

KWrite > Settings > Configure Shortcuts... > Kate Part
~/.local/share/kxmlgui5/katepart/katepart5ui.rc


Among "Global Shortcuts", "Plasma > Activate Application Launcher Widget" is also stored in
~/.config/plasma-org.kde.plasma.desktop-appletsrc
in addition to the common
~/.config/kglobalshortcutsrc

This is because "Activate Application Launcher Widget" can be also set by
Right-click "Application Launcher" > Application Launcher Settings... > Keyboard Shortcuts


The dissociation of Meta key (a.k.a. Windows Key or Apple Command Key) from the Kickoff Application Launcher (a.k.a. Start Menu) is stored in
~/.config/kwinrc

I dissociated the Meta key from the Application Launcher by the command:
Code: Select all
kwriteconfig5 --file kwinrc --group ModifierOnlyShortcuts --key Meta ""

This command adds the following two lines into "~/.config/kwinrc".
Code: Select all
[ModifierOnlyShortcuts]
Meta=


Except "kglobalshortcutsrc" and "khotkeysrc", these files store only custom shortcuts but not default shortcuts, but also store other kinds of preferences. "kglobalshortcutsrc" stores both custom and default shortcuts, but does not store other kinds of preferences. "khotkeysrc" seems similar to "kglobalshortcutsrc".



How to Find the Preference Files of Keyboard Shortcuts

First, add some custom shortcuts whose modifier key is Meta or Control, say "Meta+C" or "Ctrl+Tab", to "System Settings > Shortcuts > Standard Shortcuts" and "System Settings > Shortcuts > Global Shortcuts" and to "Configure Shortcuts" of individual applications.

Then, by the following command, conduct a content search to look for files that contain the keyword 'Meta+', 'Ctrl+' or 'Meta=', searching in the home directory ~.
Code: Select all
cd; find . -type f -print0 | xargs -0 grep -El '(Meta\+|Ctrl\+|Meta=)' | perl -pe 's|^\.|~|' | sort

The resultant files are good candidates for the files storing keyboard shortcuts. Examine each file to see whether it actually stores keyboard shortcuts.


I thank TKL-Ansi for "~/.local/share/kxmlgui5", which is the directory enclosing the files that store the custom keyboard shortcuts of individual applications. I found the other files on my own.



Back Up and Restore the Keyboard Shortcuts

Generally, the "System Settings" does not provide GUI methods to export or import settings. Under "System Settings > Shortcuts", only when "Global Shortcuts" is selected, the File popup menu emerges near the lower right corner of this System Settings window, and provides the "Import Scheme..." and "Export Scheme..." menu items. This File popup menu disappears when "Standard Shortcuts" or "Custom Shortcuts" is selected.

I need to back up not only Global Shortcuts but also other shortcuts. The following command backs up the nine preference files containing keyboard shortcuts into the archive file "KeyboardShortcut.tar.gz".
Code: Select all
cd ~; tar -czf KeyboardShortcut.tar.gz .{config/{kdeglobals,kglobalshortcutsrc,khotkeysrc,plasma-org.kde.plasma.desktop-appletsrc,kwinrc},local/share/kxmlgui5/{katepart/katepart5,konsole/{konsole,session},kwrite/kwrite}ui.rc}

Note that, as stated above, these preference files (except "kglobalshortcutsrc" and "khotkeysrc") contain not only keyboard shortcuts but also other kinds of preferences. Therefore, when these preference files are restored, not only keyboard shortcuts but also other kinds of preferences will be restored, overwriting the existing ones, which may or may not what you want. (I am thinking about writing commands to back up and restore only keyboard shortcuts without interfering with other kinds of preferences; but not now.)


To restore these preference files, do the following command with the current directory being your home directory, preferably in the rescue mode (recovery mode).
Code: Select all
tar -xf KeyboardShortcut.tar.gz -C .

The reason that this restoration should be done in the rescue mode follows. For each preference file, Plasma and other applications likely keep an extra copy in the memory besides the one on the disk. When they quit, they may possibly update the preference files by overwriting those on the disk with those in the memory. Therefore, if the preference files are restored from KeyboardShortcut.tar.gz to the disk while Plasma and other applications are running, the restored copies may be overwritten and destroyed when they quit.

Therefore, it is better to restore them while Plasma and other applications are not running. To do so, restore them in the recovery mode (rescue mode). Thus, enter the recovery mode from the GRUB menu when the computer starts up, and log in as "root". Note that, normally, the tilde (~) indicates your home directory; however, while logged in as root, ~ means "/root". Hence, you need to cd to your own home directory first. Then, execute
Code: Select all
tar -xf KeyboardShortcut.tar.gz -C .

To get out of the rescue mode, execute
Code: Select all
exit


These commands here are expected to run on bash.


KDE Plasma 5
Debian 9.4


Bookmarks



Who is online

Registered users: bartoloni, Bing [Bot], Google [Bot], Yahoo [Bot]