Created
November 26, 2018 09:16
-
-
Save ponimas/6c39c66232be04d0e421a9d054db648d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # -*- coding: utf-8 -*- | |
| import re | |
| from copy import copy | |
| from xkeysnail.transform import * | |
| # [Global modemap] Change modifier keys as in xmodmap | |
| define_modmap({Key.CAPSLOCK: Key.LEFT_CTRL}) | |
| # [Conditional modmap] Change modifier keys in certain applications | |
| # define_conditional_modmap(re.compile(r'Emacs'), { | |
| # Key.RIGHT_CTRL: Key.ESC, | |
| # }) | |
| # [Multipurpose modmap] Give a key two meanings. A normal key when pressed and | |
| # released, and a modifier key when held down with another key. See Xcape, | |
| # Carabiner and caps2esc for ideas and concept. | |
| define_multipurpose_modmap( | |
| # Enter is enter when pressed and released. Control when held down. | |
| {Key.ENTER: [Key.ENTER, Key.RIGHT_CTRL]} | |
| # Capslock is escape when pressed and released. Control when held down. | |
| # {Key.CAPSLOCK: [Key.ESC, Key.LEFT_CTRL] | |
| # To use this example, you can't remap capslock with define_modmap. | |
| ) | |
| # Ctrl+Alt+j/k to switch next/previous tab | |
| # K("C-M-j"): K("C-TAB"), | |
| # K("C-M-k"): K("C-Shift-TAB"), | |
| # # Type C-j to focus to the content | |
| # K("C-j"): K("C-f6"), | |
| # # very naive "Edit in editor" feature (just an example) | |
| # K("C-o"): [K("C-a"), K("C-c"), launch(["gedit"]), sleep(0.5), K("C-v")] | |
| # Keybindings for Firefox/Chrome | |
| browser_map = { | |
| K("M-t"): K("C-t"), | |
| K("M-r"): K("f5"), | |
| K("C-x"): {K("C-k"): K("C-w"), K("k"): K("C-w")}, | |
| } | |
| station_map = copy(browser_map) | |
| station_map.update({K("M-KEY_{}".format(i)): K("C-KEY_{}".format(i)) for i in range(9)}) | |
| station_map.update({K("M-r"): K("C-r")}) | |
| define_keymap(re.compile("Firefox|Google-chrome"), browser_map, "Firefox and Chrome") | |
| define_keymap(re.compile("Station"), station_map, "Station.app") | |
| # Keybindings for Zeal https://github.com/zealdocs/zeal/ | |
| define_keymap( | |
| re.compile("Zeal"), | |
| { | |
| # Ctrl+s to focus search area | |
| K("C-s"): K("C-k") | |
| }, | |
| "Zeal", | |
| ) | |
| # Emacs-like keybindings in non-Emacs applications | |
| define_keymap( | |
| lambda wm_class: wm_class not in ("Emacs", "URxvt", "Alacritty", "Emacs-snapshot"), | |
| { | |
| # Cursor | |
| K("C-b"): with_mark(K("left")), | |
| K("C-f"): with_mark(K("right")), | |
| K("C-p"): with_mark(K("up")), | |
| K("C-n"): with_mark(K("down")), | |
| K("C-h"): with_mark(K("backspace")), | |
| # Forward/Backward word | |
| K("M-b"): with_mark(K("C-left")), | |
| K("M-f"): with_mark(K("C-right")), | |
| # Beginning/End of line | |
| K("C-a"): with_mark(K("home")), | |
| K("C-e"): with_mark(K("end")), | |
| # Page up/down | |
| K("M-v"): with_mark(K("page_up")), | |
| K("C-v"): with_mark(K("page_down")), | |
| # Beginning/End of file | |
| K("M-Shift-comma"): with_mark(K("C-home")), | |
| K("M-Shift-dot"): with_mark(K("C-end")), | |
| # Newline | |
| K("C-m"): K("enter"), | |
| K("C-j"): K("enter"), | |
| K("C-o"): [K("enter"), K("left")], | |
| # Copy | |
| K("C-w"): [K("C-x"), set_mark(False)], | |
| K("M-w"): [K("C-c"), set_mark(False)], | |
| K("C-y"): [K("C-v"), set_mark(False)], | |
| # Delete | |
| K("C-d"): [K("delete"), set_mark(False)], | |
| K("M-d"): [K("C-delete"), set_mark(False)], | |
| # Kill line | |
| K("C-k"): [K("Shift-end"), K("C-x"), set_mark(False)], | |
| # Undo | |
| K("C-slash"): [K("C-z"), set_mark(False)], | |
| K("C-Shift-ro"): K("C-z"), | |
| # Mark | |
| K("C-space"): set_mark(True), | |
| # Search | |
| K("C-s"): K("F3"), | |
| K("C-r"): K("Shift-F3"), | |
| K("M-Shift-key_5"): K("C-h"), | |
| # Cancel | |
| K("C-g"): [K("esc"), set_mark(False)], | |
| # Escape | |
| K("C-q"): escape_next_key, | |
| # C-x YYY | |
| K("C-x"): { | |
| # C-x h (select all) | |
| K("h"): [K("C-home"), K("C-a"), set_mark(True)], | |
| # C-x C-f (open) | |
| K("C-f"): K("C-o"), | |
| # C-x C-s (save) | |
| K("C-s"): K("C-s"), | |
| # C-x k (kill tab) | |
| K("k"): K("C-f4"), | |
| # C-x C-c (exit) | |
| K("C-c"): K("C-q"), | |
| # cancel | |
| K("C-g"): pass_through_key, | |
| # C-x u (undo) | |
| K("u"): [K("C-z"), set_mark(False)], | |
| }, | |
| }, | |
| "Emacs-like keys", | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment