Skip to content

Instantly share code, notes, and snippets.

@ryan-mooore
Forked from pkazmier/.skhdrc
Last active May 2, 2024 14:16
Show Gist options
  • Save ryan-mooore/016b0d10e3dcc138e429570d0752fbad to your computer and use it in GitHub Desktop.
Save ryan-mooore/016b0d10e3dcc138e429570d0752fbad to your computer and use it in GitHub Desktop.
# Updated from https://gist.github.com/pkazmier to support yabai
#
# The following configuration heavily leverages modal keymaps to minimize the
# pollution of global keybindings. In addition, the modal keymaps facilitate
# the consistent use of the same keybindings across different modes. For
# example, this configuration uses 'h', 'l', 'j', and 'k' to represent west,
# east, south, and north when: changing focus, warping windows, resizing
# windows, swapping windows, and moving floating windows. Those four keys are
# mapped differently depending on the current mode to provide a consistent user
# experience.
#
# Six different modes are provided in this configuration in addition to the
# default mode. The modes are tailored to their respective operations. Common
# operations are generally available without the need of any modifier keys.
# When modifier keys are used, they are for infrequent actions or size related
# actions. Entry into the modal system is via Ctrl - Space, which enters FOCUS
# mode. From there, any of the other modes can be activated with a single
# keypress.
#
# The following is a high-level summary of the keybindngs:
#
# GLOBAL KEYBINDINGS:
# ctrl - space Enter FOCUS mode
# ctrl - return Open a Terminal
# cmd - return Open a floating Terminal
#
#
# KEYBINDINGS AVAILABLE IN ALL MODES:
# escape Exit current mode
# f Enter FOCUS mode
# g Enter GRID mode
# s Enter SWAP mode
# r Enter RESIZE mode
# w Enter WARP mode
# shift - w Enter WARP NO FOLLOW mode
#
# q Close window
# e Equalize window sizes
# m Toggle fullscreen
# o Toggle offset
# p Toggle parent zoom
# i Toggle split
# t Toggle float
# x Mirror horizontal
# y Mirror vertical
# space Rotate desktop 90
# shift - space Rotate desktop 270
#
#
# FOCUS MODE KEYBINDINGS:
# return, h, j, k, l Focus window (largest, west, south, north, east)
# cmd + h, j, k, l Set insertion point (west, south, north, east)
# 1, 2, 3, tab, shift - tab Focus monitor (1, 2, 3, next, prev)
# cmd + 1, 2, 3, tab, shift - tab Focus desktop (1, 2, 3, next, prev)
# cmd - t Float next window
# cmd - return Cancel insertion point and float next window
# cmd + b, m, f Set desktop layout mode (bsp, monacle, float)
#
#
# WARP MODE KEYBINDINGS:
# return, h, j, k, l Warp window (largest, west, south, north, east)
# 1, 2, 3, tab, shift - tab Warp to monitor (1, 2, 3, next, prev) and follow
# cmd + 1, 2, 3, tab, shift - tab Warp to desktop (1, 2, 3, next, prev) and follow
#
#
# WARP NO FOLLOW MODE KEYBINDINGS:
# return, h, j, k, l Warp window (largest, west, south, north, east)
# 1, 2, 3, tab, shift - tab Warp to monitor (1, 2, 3, next, prev) and do not follow
# cmd + 1, 2, 3, tab, shift - tab Warp to desktop (1, 2, 3, next, prev) and do not follow
#
#
# SWAP MODE KEYBINDINGS:
# return, h, j, k, l Swap window (largest, west, south, north, east)
#
#
# RESIZE MODE KEYBINDINGS:
# h, j, k, l Increase window (west, south, north, east)
# shift + h, j, k, l Decrease window (west, south, north, east)
#
#
# GRID MODE KEYBINDINGS:
# return, h, j, k, l Resize & move floating window (center, left, bottom, top, right)
# shift + return, h, j, k, l Resize smaller & move floating window (center, left, bottom, top, right)
# cmd + return, h, j, k, l Resize even smaller & move floating window (center, top-left, bottom-left, bottom-right, top-right)
#
:: default : yabai -m config active_window_border_color 0xff61afef
:: focus @ : yabai -m config active_window_border_color 0xffe06c75 # Focus window, desktop, monitors
:: grid @ : yabai -m config active_window_border_color 0xff56b6c2 # Floating window layout
:: swap @ : yabai -m config active_window_border_color 0xffc678dd # Swap windows
:: warp @ : yabai -m config active_window_border_color 0xffe5c07b # Warp and send to desktop/monitors
:: warpnf @ : yabai -m config active_window_border_color 0xffd19a66 # Same, but don't follow focus
:: resize @ : yabai -m config active_window_border_color 0xff98c379 # Resize window operations
# CTRL-SPACE is the global hotkey to toggle in/out of modal mode. Entry is
# always to FOCUS mode. Getting out of any mode can also be done with ESCAPE.
default < ctrl - space ; focus
focus, grid, swap, warp, warpnf, resize < ctrl - space ; default
focus, grid, swap, warp, warpnf, resize < escape ; default
# Once in FOCUS mode (or any other mode other than default), you can switch
# modes with single keystroke. (mnemonic: letter corresponds to first letter of
# mode name, with exception of warpnf, which is a variant invoked with shift)
focus, grid, swap, warp, warpnf, resize < f ; focus
focus, grid, swap, warp, warpnf, resize < g ; grid
focus, grid, swap, warp, warpnf, resize < s ; swap
focus, grid, swap, warp, warpnf, resize < r ; resize
focus, grid, swap, warp, warpnf, resize < w ; warp
focus, grid, swap, warp, warpnf, resize < shift - w ; warpnf
# The following keybindings are available in all modes.
focus, grid, swap, warp, warpnf, resize < space : yabai -m space --rotate 90
focus, grid, swap, warp, warpnf, resize < shift - space : yabai -m space --rotate 270
focus, grid, swap, warp, warpnf, resize < x : yabai -m space --mirror x-axis
focus, grid, swap, warp, warpnf, resize < y : yabai -m space --mirror y-axis
focus, grid, swap, warp, warpnf, resize < o : yabai -m space --toggle gap; yabai -m space --toggle padding # mnemonic: _o_ffset
focus, grid, swap, warp, warpnf, resize < b : yabai -m space --balance # mnemonic: _b_alance
focus, grid, swap, warp, warpnf, resize < m : yabai -m window --toggle native-fullscreen # mnemonic: _m_onacle
focus, grid, swap, warp, warpnf, resize < q : yabai -m window --close # mnemonic: _q_uit
focus, grid, swap, warp, warpnf, resize < p : yabai -m window --toggle zoom-parent # mnemonic: _p_arent
focus, grid, swap, warp, warpnf, resize < i : yabai -m window --toggle split # mnemonic: couldn't think of one!
focus, grid, swap, warp, warpnf, resize < t : yabai -m window --toggle float # mnemonic: floa_t_
# Global hotkeys which I limit so as to not pollute the global namespace
default < ctrl - return : open -na Terminal; yabai -m space --balance
default < cmd - return : open -na Terminal;
# Change focus using standard vi directional keys. Enter changes focus to the
# largest window. You'll see this theme repeated over and over again. Since this
# is such a common operation, no modifier keys are used.
focus < k : yabai -m window --focus north
focus < j : yabai -m window --focus south
focus < l : yabai -m window --focus east
focus < h : yabai -m window --focus west
focus < return : yabai -m window --focus largest
# Change the next insertion point to be something other than the default (left)
# using standard vi directional keys with the Cmd modifier. In addition, to
# make the next window a floating window, we bind cmd - t (using same mnemonic
# as above). As these operations are intended for the next window that is
# opened, we exit FOCUS mode immediately.
focus < cmd - k : yabai -m window --insert north; skhd -k "ctrl - space"
focus < cmd - j : yabai -m window --insert south; skhd -k "ctrl - space"
focus < cmd - l : yabai -m window --insert east; skhd -k "ctrl - space"
focus < cmd - h : yabai -m window --insert west; skhd -k "ctrl - space"
focus < cmd - t : yabai -m window --insert stack; skhd -k "ctrl - space"
# Change the monitor focus using numbers corresponding to monitor or cycle
# through the monitors using tab and shift - tab combination. You'll see this
# pattern repeated when we get WARP moded as well. The non-modified keys will
# warp to a monitor, and prefixing with cmd will warp to desktop. Again, the
# goal was to aim for consistency.
focus < 1 : yabai -m display --focus 1
focus < 2 : yabai -m display --focus 2
focus < 3 : yabai -m display --focus 3
focus < tab : yabai -m display --focus next
focus < shift - tab : yabai -m display --focus prev
# Prefix the above with cmd to change the desktop focus using numbers
# corresponding to desktop or cycle through the monitors using tab and shift -
# tab combination. Note: we do not use chunkwm's fast desktop switching as it
# requires chunk-sa (which injects code into the Dock.app). Insead, we fake
# this by sending keystrokes to mission control, but in order to do so, me must
# exit FOCUS mode, send the gloabl mission control keystroke, and then re-enter
# FOCUS mode, so we remain in focus mode. It's very likely that you'll want to
# change focus of windows after switching desktops, which is why we want to get
# back to FOCUS mode. Finally, due timing issues, we introduce a sleep as the
# standard mode commands are executed before mission control is done with its
# animation. Direct jumping to a window is faster than cycling through
# desktops, so the sleep delays are different.
focus < cmd - 1 : yabai -m space --focus 1; yabai -m config active_window_border_color 0xffe06c75
focus < cmd - 2 : yabai -m space --focus 2; yabai -m config active_window_border_color 0xffe06c75
focus < cmd - 3 : yabai -m space --focus 3; yabai -m config active_window_border_color 0xffe06c75
focus < cmd - tab : yabai -m space --focus next; yabai -m config active_window_border_color 0xffe06c75
focus < cmd + shift - tab : yabai -m space --focus prev; yabai -m config active_window_border_color 0xffe06c75
# Change the layout mode of a desktop to one of the three supported modes.
focus < cmd - b : yabai -m space --layout bsp # mnemonic: _b_sp
focus < cmd - s : yabai -m space --layout stack # mnemonic: _s_tack
focus < cmd - f : yabai -m space --layout float # mnemonic: _f_loat
# Grid mode bindings are to resize and place floating windows on your desktop
# in well known positions. The standard non-modified keys are used to resize
# the window to the top-half, bottom-half, right-half, left-half, and center of
# screen respectively.
grid < k : yabai -m window --grid 2:1:0:0:1:1
grid < j : yabai -m window --grid 2:1:0:1:1:1
grid < l : yabai -m window --grid 1:2:1:0:1:1
grid < h : yabai -m window --grid 1:2:0:0:1:1
grid < return : yabai -m window --grid 6:6:1:1:4:4
# Prefix the above with shift modifier to resize a bit smaller: top-third,
# bottom-third, left-third, right-third, and smaller center.
grid < shift - k : yabai -m window --grid 3:1:0:0:1:1
grid < shift - j : yabai -m window --grid 3:1:0:2:1:1
grid < shift - l : yabai -m window --grid 1:3:2:0:1:1
grid < shift - h : yabai -m window --grid 1:3:0:0:1:1
grid < shift - return : yabai -m window --grid 4:4:1:1:2:2
# Prefix with cmd to resize even smaller and place in corners or center.
grid < cmd - k : yabai -m window --grid 5:5:4:4:1:1
grid < cmd - j : yabai -m window --grid 5:5:0:4:1:1
grid < cmd - l : yabai -m window --grid 5:5:4:0:1:1
grid < cmd - h : yabai -m window --grid 5:5:0:0:1:1
grid < cmd - return : yabai -m window --grid 6:6:2:2:2:2
# Swap windows using standard vi directional keys.
swap < k : yabai -m window --swap north
swap < j : yabai -m window --swap south
swap < l : yabai -m window --swap east
swap < h : yabai -m window --swap west
swap < return : yabai -m window --swap largest
# Warp windows using standard vi directional keys. These bindings are the same
# whether you are in WARP or WARPNF mode.
warp, warpnf < k : yabai -m window --warp north
warp, warpnf < j : yabai -m window --warp south
warp, warpnf < l : yabai -m window --warp east
warp, warpnf < h : yabai -m window --warp west
warp, warpnf < return : yabai -m window --warp largest
# Warp window to monitor and follow.
warp < 1 : yabai -m window --display 1; yabai -m display --focus 1
warp < 2 : yabai -m window --display 2; yabai -m display --focus 2
warp < 3 : yabai -m window --display 3; yabai -m display --focus 3
warp < tab : yabai -m window --display next; yabai -m display --focus next
warp < shift - tab : yabai -m window --display prev; yabai -m display --focus prev
# Prefix with cmd to warp window to desktop and follow.
warp < cmd - 1 : yabai -m window --space 1; yabai -m space --focus 1; yabai -m config active_window_border_color 0xff98c379
warp < cmd - 2 : yabai -m window --space 2; yabai -m space --focus 2; yabai -m config active_window_border_color 0xff98c379
warp < cmd - 3 : yabai -m window --space 3; yabai -m space --focus 3; yabai -m config active_window_border_color 0xff98c379
warp < cmd - tab : yabai -m window --space next; yabai -m space --focus next; yabai -m config active_window_border_color 0xff98c379
warp < cmd + shift - tab : yabai -m window --space prev; yabai -m space --focus prev; yabai -m config active_window_border_color 0xff98c379
# Warp window to monitor, but do NOT follow.
warpnf < 1 : yabai -m window --display 1
warpnf < 2 : yabai -m window --display 2
warpnf < 3 : yabai -m window --display 3
warpnf < tab : yabai -m window --display next
warpnf < shift - tab : yabai -m window --display prev
# Prefix with cmd to warp windown to monitor, but do NOT follow.
warpnf < cmd - 1 : yabai -m window --space 1
warpnf < cmd - 2 : yabai -m window --space 2
warpnf < cmd - 3 : yabai -m window --space 3
warpnf < cmd - tab : yabai -m window --space next
warpnf < cmd + shift - tab : yabai -m window --space prev
# Increase size of window using standard vi directional keys.
resize < k : yabai -m window --ratio rel:0.05; yabai -m window --resize top:0:-10
resize < j : yabai -m window --ratio rel:0.05; yabai -m window --resize bottom:0:10
resize < l : yabai -m window --ratio rel:0.05; yabai -m window --resize right:10:0
resize < h : yabai -m window --ratio rel:0.05; yabai -m window --resize left:-10:0
# Prefix the above with shift to decrease size of window using standard vi
# directional keys.
resize < shift - k : yabai -m window --ratio rel:-0.05; yabai -m window --resize top:0:10
resize < shift - j : yabai -m window --ratio rel:-0.05; yabai -m window --resize bottom:0:-10
resize < shift - l : yabai -m window --ratio rel:-0.05; yabai -m window --resize right:-10:0
resize < shift - h : yabai -m window --ratio rel:-0.05; yabai -m window --resize left:10:0
@SethHorsley
Copy link

this is great! Thank you for porting this over 💯 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment