How to configure a Mac-like set of keybindings in cwm and alacritty
Objective
In MacOS, keyboard shortcuts mostly use the ‘cmd’ key. This is convenient in Unix mainly because Ctrl- shortcuts are commonly used in the command line. My goal is to leave the ‘ctrl’ key free to be used with the command line while useing ‘super’ as a modifier key for keyboard shortcuts, includeing Ctrl-C/Ctrl-V cut/copy/paste. As I am used to the MacOS keyboard layout, I would also like to use the modifier keys in a similar arrangment as they appear on a Mac keyboard.
I’ll accomplish this by swapping Ctrl and Super, and then modifying my terminal and window manager keybindings appropriately.
Configuring
X Key Mapping
The first thing to do is to modify the key map in Xorg. I will use setxkbmap to do this in X natively by placing the modifier mapping in my .xinitirc. For a Mac layout keyboard use the command:
# Swap Left Ctrl and Left Super (Mac layout)
setxkbmap -option ctrl:swap_lwin_lctl
and for a PC layout:
# Swap modifier keys to Super-Alt-Control (PC Layout)
setxkbmap -option ctrl:swap_lalt_lctl_lwin
This will effectively put the left-hand modifier keys in the order of:
Super - Alt - Control
Alacritty Keymapping
With Control in the place where the Mac ‘Cmd’ key usually sits, most window manager keybindings, as well as keybindings in most apps (Firefox, etc) will work as they do on a Mac. The command line still presents a challenge. Luckily my favorite terminal emulator, which I have configured exactly to my liking in my window manager environment, supports key-remapping in it’s config file.
The following configuration passes ‘ctrl-’ modified keystrokes through as if they were unmodified, except for the cut/copy/paste commands. For those it will pass the appropriate command. It will also pass ‘Super’ modified keystrokes through as if they were ctrl- modified.
[[keyboard.bindings]]
key = "At"
mods = "Control"
chars = "@"
[[keyboard.bindings]]
key = "A"
mods = "Control"
chars = "a"
[[keyboard.bindings]]
key = "B"
mods = "Control"
chars = "b"
[[keyboard.bindings]]
key = "C"
mods = "Control"
action = "Copy"
[[keyboard.bindings]]
key = "D"
mods = "Control"
chars = "d"
[[keyboard.bindings]]
key = "E"
mods = "Control"
chars = "e"
[[keyboard.bindings]]
key = "F"
mods = "Control"
action = "SearchForward"
[[keyboard.bindings]]
key = "F"
mods = "Control"
mode = "~Search"
action = "SearchForward"
[[keyboard.bindings]]
key = "F"
mods = "Control|Shift"
action = "SearchBackward"
[[keyboard.bindings]]
key = "F"
mods = "Control|Shift"
mode = "~Search"
action = "SearchBackward"
[[keyboard.bindings]]
key = "G"
mods = "Control"
chars = "g"
[[keyboard.bindings]]
key = "H"
mods = "Control"
chars = "h"
[[keyboard.bindings]]
key = "I"
mods = "Control"
chars = "i"
[[keyboard.bindings]]
key = "J"
mods = "Control"
chars = "j"
[[keyboard.bindings]]
key = "K"
mods = "Control"
chars = "k"
[[keyboard.bindings]]
key = "L"
mods = "Control"
chars = "l"
[[keyboard.bindings]]
key = "M"
mods = "Control"
chars = "m"
[[keyboard.bindings]]
key = "N"
mods = "Control"
action = "CreateNewWindow"
[[keyboard.bindings]]
key = "O"
mods = "Control"
chars = "o"
[[keyboard.bindings]]
key = "P"
mods = "Control"
chars = "p"
[[keyboard.bindings]]
key = "Q"
mods = "Control"
action = "Quit"
[[keyboard.bindings]]
key = "R"
mods = "Control"
chars = "r"
[[keyboard.bindings]]
key = "S"
mods = "Control"
chars = "s"
[[keyboard.bindings]]
key = "T"
mods = "Control"
chars = "t"
[[keyboard.bindings]]
key = "U"
mods = "Control"
chars = "u"
[[keyboard.bindings]]
key = "V"
mods = "Control"
action = "Paste"
[[keyboard.bindings]]
key = "W"
mods = "Control"
action = "Quit"
[[keyboard.bindings]]
key = "X"
mods = "Control"
chars = "Cut"
[[keyboard.bindings]]
key = "Y"
mods = "Control"
chars = "y"
[[keyboard.bindings]]
key = "Z"
mods = "Control"
chars = "z"
[[keyboard.bindings]]
key = "LBracket"
mods = "Control"
chars = "["
[[keyboard.bindings]]
key = "Backslash"
mods = "Control"
chars = "\\"
[[keyboard.bindings]]
key = "RBracket"
mods = "Control"
chars = "]"
[[keyboard.bindings]]
key = "`"
mods = "Control"
chars = "^"
[[keyboard.bindings]]
key = "_"
mods = "Control"
chars = "_"
[[keyboard.bindings]]
key = "At"
mods = "Super"
chars = "\u0000"
[[keyboard.bindings]]
key = "A"
mods = "Super"
chars = "\u0001"
[[keyboard.bindings]]
key = "B"
mods = "Super"
chars = "\u0002"
[[keyboard.bindings]]
key = "C"
mods = "Super"
chars = "\u0003"
[[keyboard.bindings]]
key = "D"
mods = "Super"
chars = "\u0004"
[[keyboard.bindings]]
key = "E"
mods = "Super"
chars = "\u0005"
[[keyboard.bindings]]
key = "F"
mods = "Super"
chars = "\u0006"
[[keyboard.bindings]]
key = "G"
mods = "Super"
chars = "\u0007"
[[keyboard.bindings]]
key = "H"
mods = "Super"
chars = "\b"
[[keyboard.bindings]]
key = "I"
mods = "Super"
chars = "\t"
[[keyboard.bindings]]
key = "J"
mods = "Super"
chars = """
"""
[[keyboard.bindings]]
key = "K"
mods = "Super"
chars = "\u000b"
[[keyboard.bindings]]
key = "L"
mods = "Super"
chars = "\f"
[[keyboard.bindings]]
key = "M"
mods = "Super"
chars = "\r"
[[keyboard.bindings]]
key = "N"
mods = "Super"
chars = "\u000e"
[[keyboard.bindings]]
key = "O"
mods = "Super"
chars = "\u000f"
[[keyboard.bindings]]
key = "P"
mods = "Super"
chars = "\u0010"
[[keyboard.bindings]]
key = "Q"
mods = "Super"
chars = "\u0011"
[[keyboard.bindings]]
key = "R"
mods = "Super"
chars = "\u0012"
[[keyboard.bindings]]
key = "S"
mods = "Super"
chars = "\u0013"
[[keyboard.bindings]]
key = "T"
mods = "Super"
chars = "\u0014"
[[keyboard.bindings]]
key = "U"
mods = "Super"
chars = "\u0015"
[[keyboard.bindings]]
key = "V"
mods = "Super"
chars = "\u0016"
[[keyboard.bindings]]
key = "W"
mods = "Super"
chars = "\u0017"
[[keyboard.bindings]]
key = "X"
mods = "Super"
chars = "\u0018"
[[keyboard.bindings]]
key = "Y"
mods = "Super"
chars = "\u0019"
[[keyboard.bindings]]
key = "Z"
mods = "Super"
chars = "\u001a"
[[keyboard.bindings]]
key = "LBracket"
mods = "Super"
chars = "\u001b"
[[keyboard.bindings]]
key = "Backslash"
mods = "Super"
chars = "\u001c"
[[keyboard.bindings]]
key = "RBracket"
mods = "Super"
chars = "\u001d"
[[keyboard.bindings]]
key = "`"
mods = "Super"
chars = "\u001e"
[[keyboard.bindings]]
key = "_"
mods = "Super"
chars = "\u001f"
CWM
For this configuration, I simply swap ‘Ctrl’ and ‘Super’ in my keybinding list to make my cwm keybindings work as they did before.
# Key bindings (Ctrl and Super Swapped)
unbind-key all
bind-key Print "scrot"
bind-key M-Print "scrot --select"
bind-key C-Return "alacritty"
bind-key C-space menu-exec
bind-key CM-space menu-cmd
bind-key CS-e quit
bind-key CS-r restart
bind-key C4-equal window-vmaximize
bind-key C4S-equal window-hmaximize
bind-key C-equal window-vtile
bind-key CS-equal window-htile
bind-key C-h window-hide
bind-key M-Down window-lower
bind-key M-Up window-raise
bind-key M-Tab window-cycle
bind-key MS-Tab window-rcycle
bind-key C-x window-close
bind-key C-f window-fullscreen
bind-key C-s window-stick
bind-key C-m window-maximize
bind-key C-Up window-move-up-big
bind-key C-Down window-move-down-big
bind-key C-Right window-move-right-big
bind-key C-Left window-move-left-big
bind-key CS-Up window-move-up
bind-key CS-Down window-move-down
bind-key CS-Right window-move-right
bind-key CS-Left window-move-left
bind-key C4-Up window-resize-up-big
bind-key C4-Down window-resize-down-big
bind-key C4-Right window-resize-right-big
bind-key C4-Left window-resize-left-big
bind-key C4S-Up window-resize-up
bind-key C4S-Down window-resize-down
bind-key C4S-Right window-resize-right
bind-key C4S-Left window-resize-left
bind-key C-period menu-ssh
#bind-key C4M-l "xscreensaver-command -lock"
bind-key C-l "xscreensaver-command -lock"
bind-key M-l "xscreensaver-command -lock"
bind-key C-1 group-only-1
bind-key C-2 group-only-2
bind-key C-3 group-only-3
bind-key C-4 group-only-4
bind-key CS-1 window-movetogroup-1
bind-key CS-2 window-movetogroup-2
bind-key CS-3 window-movetogroup-3
bind-key CS-4 window-movetogroup-4
bind-key 4-Right group-cycle
bind-key 4-Left group-rcycle
unbind-key 4-o
unbind-key CM-equal
unbind-key CMS-equal
# Mouse bindings
bind-mouse M-2 window-lower
bind-mouse M-1 window-resize
bind-mouse C-1 window-move