Xkeysnail that can convert keyboard shortcuts is wonderful, so let's use it.
On Mac, you can use Ctrl + a
to move to the beginning of a line and Ctrl + k
to cut to the end of a line, not just in the emacs terminal, but everywhere. I want to achieve this on Ubuntu as well. I wasn't quite happy with gnome-tweak-tool
key-theme = Emacs, which implements emacs key bindings in Gnome; it was overwritten by Windows-like shortcuts in the browser, especially in Jupyter Notebook with Ctrl-a
. It's hard to say "select the whole". xkeysnail makes Ctrl + a
look like the Home key to move to the beginning of a line, so it can be used in a browser (as long as the web app supports normal windows styles). There is no Ubuntu element in particular and it can be used in Linux in general.
$ sudo apt install python3-pip
$ sudo pip3 install xkeysnail
pip
is Python's library package management software.
For the time being, it can be anywhere, so create config.py
. Click here for official config.py.
In the directory where that config.py is:
$ xhost +SI:localuser:root
$ sudo xkeysnail config.py
Troubleshooting
If you do pip3 install ...
instead of sudo pip3 install ...
, it will be installed in ~ / .local / bin / xkeysnail
and your PATH is probably not in your path.
$ pip3 show xkeysnail
(Omitted)
Location: /usr/local/lib/python3.6/dist-packages
You can find the installation destination by looking at. If you are using many environments such as conda and pyenv, be careful which environment you installed. The environment may differ depending on whether you use sudo or not. To redo the forgotten sudo pip
$ pip3 uninstall xkeysnail
$ sudo pip3 install xkeysnail
Alternatively, pass it through the PATH if you like, or execute it with the absolute PATH.
If you look higher, you will find more specific errors. For example
FileNotFoundError: [Errno 2] No such file or directory: 'config.pu'
Wrong the file name of config.py. You may have the wrong key name in config.py.
It appears if you have not done xhost +
.
⌘ space
to switch between English and Japanese languages, and use it separately from the emacs mark set ctrl-space
. In other words, setting command = ctrl is overkill.
# -*- coding: utf-8 -*-
import string
from xkeysnail.transform import *
# define timeout for multipurpose_modmap
define_timeout(1)
# [Global modemap] Change modifier keys as in xmodmap
define_modmap({
Key.CAPSLOCK: Key.ESC, #Use caps lock as Esc. There may be many Ctrl groups
Key.LEFT_META: Key.RIGHT_META, #overview Disable:Left ⌘ → Right ⌘
})
# Always paste with ⌘-v including terminals
#None is unconditional=Means all applications
define_keymap(None, {
K("Super-v"): [K("C-v"), set_mark(False)],
}, "Paste")
# Mac-like keybindings outside emacs and terminals
#Minimal emacs keybinding.
#Official config.py is more emacs. C-x C-s → You can also save.
mapping = {
# Beginning/End of line
K("C-a"): with_mark(K("home")),
K("C-e"): with_mark(K("end")),
# Delete
K("C-d"): [K("delete"), set_mark(False)],
K("C-h"): with_mark(K("backspace")),
# Kill line
K("C-k"): [K("Shift-end"), K("C-x"), set_mark(False)],
}
#Ctrl ⌘α for all alphabets α+Suppose you are pressing α
for c in string.ascii_lowercase:
mapping[K('Super-' + c)] = K('C-' + c)
#Change the shortcut outside of Emacs and Terminal. Hyper is the name of the terminal application I'm using.
define_keymap(lambda wm_class: wm_class not in ("Emacs", "Hyper", "Gnome-terminal"),
mapping, "Mac-like")
You can see it by looking at the standard output of the terminal where ** wm_class ** is running xkeysnail with the application name. The display of this WM_CLASS and keys is suppressed by adding the xkeysnail -q option.
For those unfamiliar with Python.
Comment from #
to the end of the line.
" string "
or 'string'
is OKA data structure that stores Key-Value pairs; shortcuts you want to define: used to give shortcuts to be executed
.
d = {key1: value1.
key2: value2,
key3: value3}
It's okay to add a comma (trailing comma) at the end, or not {key3: value3,}
.
Can be added after creation:
d[key4] = value4
#### Tuple, list, set
```python
wm_class not in ("Hyper", "Gnome-terminal", "Emacs")
String wm_True if class is none of the three. By the negation operator not
not (wm_class in ("Hyper", "Gnome-terminal", "Emacs"))
Same as. If you want to make it True
wm_class in ("Hyper", "Gnome-terminal", "Emacs")
("a", "b", "c")Is an array that cannot be modifiedtuple.An array that you can change if you don't care about the detailslist ["a", "b", "c"]Also setset {"a", "b", "c"}Is the same.
If one
wm_class == "Hyper" # True if equal
wm_class! = "Hyper" # True if not equal
But it is good. Don't forget the last comma when using a single element tuple:
wm_class in ("Hyper",)
Without commas
wm_class in "Hyper"
The meaning changes as it becomes the same as "wm_class is"Hyper"Is it a substring? Will mean.
"ype" in "Hyper" # => True
"ype" in ("Hyper") # => True, ("Hyper") = "Hyper"
"type" in ("Hyper",) # => False, "ype" is "Hyper"
It is not an element of a set consisting of one element #.
#####Anonymous function lambda
f = lambda x: x**2
Is
def f(x):
return x**2
Same as. Application name wm_Used to define a function that returns whether to change a keyboard shortcut for a class.
Application namewm_classYou can change whether to convert the shortcut by.
def define_keymap(condition, mappings: dict, name: str):
conditionsconditionDictionary ifmappingsPerforms the shortcut conversion defined in.nameIs the name of any setting.
There are three ways to specify condition:
condition:
None: Apply unconditionally
Function: A function that takes the application name wm_class and returns True / False
Regular expression: Regular expression that wm_class should match (details omitted)
Key.CAPSLOCK
AndKey.ESC
The list of thingskey.pyIt is written in.
f Key |
---|
ESC |
TAB |
CAPSLOCK |
LEFT_CTRL, RIGHT_CTRL |
LEFT_SHIFT, RIGHT_SHIFT |
Key | Apple Magic keyboard | Windows keyboard |
---|---|---|
LEFT_META, RIGHT_META | command ⌘ | Win key |
LEFT_ALT, RIGHT_ALT | option ⌥ | Alt |
##K function
K("C-b")With Ctrl+Represents b. C can be Ctrl or can be limited to left or right by adding LR.You can see how to write it by pressing a key and looking at the standard output of xkeysnail..The Modifier key also has a generic term or alias (Win can be Super, etc.) when it can be left or right..
Modifier key | str for K |
---|---|
Ctrl ^ | C, Ctrl, LC, RC, LCtrl, RCtrl |
Shift | Shift, LShift, RShift |
Win/command ⌘ | Win, Super, LWin, RWin, LSuper, RSuper |
Alt/option ⌥ | Alt, M, LAlt, RAlt, RM, LM |
reference: create_modifiers_from_strings(modifier_strs) in transform.py.
##Automatic start
If the settings are complete and it works, I want to run it automatically when the computer starts. For the time being:
https://hidakatsuya.hateblo.jp/entry/2019/11/20/215608
Author's article: https://qiita.com/mooz@github/items/c5f25f27847333dd0b37 GitHub: https://github.com/mooz/xkeysnail
Recommended Posts