Tricky way to trigger Meta+n in Alacritty on MacOS

Pre

Getting bored for using the same terminal all the time, time to move on to another one.
This time will be Alacritty.
The first trouble is that Alacritty won’t treat Option as Meta, it just don’t provide you this option.
check the issues on its github repository, you’ll find something like the following:

1
2
3
4
5
6
7
8
key_bindings:
- { key: H, mods: Alt, chars: "\x1bh" }
- { key: I, mods: Alt, chars: "\x1bi" }
- { key: J, mods: Alt, chars: "\x1bj" }
- { key: K, mods: Alt, chars: "\x1bk" }
- { key: L, mods: Alt, chars: "\x1bl" }
- { key: M, mods: Alt, chars: "\x1bm" }
- { key: N, mods: Alt, chars: "\x1bn" }

It almost cover everything.
Things semm perfect until I found Alt+i/u/e/n won’t work.

Issue

on MacOS in English input method option+n will prompt a “˜” symbol, and waiting for the next keystroke to see if it can input a char that can be modified by “˜”, which will break the keymap proceeding
and this keymap will never get chance to be execute:

1
# - { key: N,        mods: Alt,     chars: "\x1bn"                       }

Looking into the issues, didn’t find useful information, and it seems the author will do the “treat option as meta” later in the future.
So, what’s now?

Solution

Karabiner came to my mind. Karabiner, a cross-platform keymap tool.
Since the issue can’t be solved in Alacritty itself, I can only count on some tool outside of it.
if I can manage to avoid option-n keystroke and map it to a middle keybinding, then the “˜” won’t shown, then map this keyBinding to the desired chars code in the Alacritty.
fortunately Karabiner and Alacritty can do this for me.

flowchart TB;

A(Alt+n) x-.-x |option+n will prompt a symbol to break the proceeding| C

subgraph Karabiner
    A --> |map| B[Command+n] 
end
B --- B'
subgraph Alacritty
    B'[Command+n] --> |map| C("\ x1bn")
end

Karabiner will map left_option+n to left_command+n, so you don’t have to
literally press Command+n to trigger Meta+n, just do as the natural way
pressing the Alt+n, and karabiner and alacritty will ensure the Meta+n
trigger for you.

Step

Config is simple

1
2
# alacritty.yml
- { key: N, mods: Command, chars: "\x1bn" }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# alacritty_karabiner.json
{
"title": " Alacritty",
"rules": [
{
"description": "Alacritty: alt+n send command+n",
"manipulators": [
{
"type": "basic",
"from": {
"key_code": "n",
"modifiers": {
"mandatory": [
"left_option"
],
"optional": [
"any"
]
}
},
"to": [
{
"key_code": "n",
"modifiers":[
"left_command"
]
}
],
"conditions": [
{
"type": "frontmost_application_if",
"bundle_identifiers": [
"org.alacritty"
]
}
]
}
]
}
]
}