I’ve been using the built-in input method on macOS for a while, and it’s pretty good, it is fast and doesn’t have many fancy features. In my daily work, I’ve gotten used to coding and searching in English. I rarely use obscure Chinese words, nor do I need to use internet slang. However, the quality of the first line of candidate words in Chinese can be quite poor, requiring me to use [], arrow keys, or the touchpad/mouse to select words.
I use VIM (a highly customizable ancient editor) a lot in my daily work, and I’ve formed muscle memory for VIM’s compact key usage and many shortcuts (I can hardly remember any shortcuts without VIM), and typing tends to be a time when my thoughts are most concentrated. After switching to the unfamiliar built-in input method on macOS, I can clearly feel that word selection is consuming my limited attention (maybe I’m getting old).
Fortunately, Karabiner-Elements can solve this problem. It’s a powerful and stable keyboard customizer for macOS.
In the built-in Chinese input method on macOS, []
is used for scrolling up and down, with the same function as the up and down arrow keys. The left and right arrow keys are used for word selection left and right. As long as you set a few shortcuts that are consistent with the functions of []
/arrow keys according to your habits, you can greatly enhance the efficiency of word selection in Chinese input.
It’s easy to achieve this in Karabiner. The following configuration maps the CTRL + N
combination key to the down arrow ↓:
{
"from": {
"key_code": "n",
"modifiers": {
"mandatory": [
"left_control"
]
}
},
"to": [
{
"key_code": "down_arrow"
}
]
}
Map CTRL + K
to the up arrow ↑:
{
"from": {
"key_code": "k",
"modifiers": {
"mandatory": [
"control"
]
}
},
"to": [
{
"key_code": "up_arrow"
}
]
}
The condition for mapping only when switching to Chinese or other input methods:
"conditions": [
{
"input_sources": [
{
"language": "^zh-Hans$"
},
{
"language": "^zh-Hant$"
},
{
"language": "^yue-Hant$"
},
{
"language": "^ja$"
}
],
"type": "input_source_if"
}
]
You can combine multiple rules and conditions through complex modifications. Here is a configuration with personal preferences, divided into three groups:
- Use
CTRL + N
to scroll down/move to the next line, andCTRL + P
for the opposite- I replace the
CTRL
and Caps Lock ⇪ on all my keyboards, because I hardly use Caps Lock andCTRL
is used very frequently. The convenience of using them is inversely proportional to the frequency of use - The same combination keys are used for code completion. Most editors can use these shortcuts for up and down movement, so there is no extra cognitive load when switching
- Word selection left and right is not set, because I think using number keys for word selection on the same line is faster in most cases
- I replace the
- Map
CTRL + H/J/K/L
to the left, down, up, right arrows respectively, e.g.,CTRL + K
has the same function asCTRL + P
mentioned aboveH/J/K/L
is used as the cursor movement method in normal mode in VIM, which can be switched seamlessly- This makes up for the “deficiency” of the first group not having left and right word selection
- Use
TAB
to select the next candidate word, andSHIFT + TAB
to select the previous candidate word- Automatically move to the next or previous line after exhausting one line
The detailed configuration is not posted here, click these words to quickly launch and import into Karabiner. Or download it locally, edit as needed, and then put it in the ~/.config/karabiner/assets/complex_modifications/ directory. Finally, you need to manually enable the rules.
Tips:
- Most editors support using
CTRL + P/N
to move the cursor up and down, so it’s better not to map them to[]
but to the up and down arrow keys, otherwise moving up and down may turn into[[[]]
character input.- Most editors support the following cursor movement shortcuts:
CTRL + P
moves upCTRL + N
moves downCTRL + B
moves left/backwardCTRL + F
moves right/forwardCTRL + A
moves to the beginning of the lineCTRL + E
moves to the end of the line
- Most editors support the following cursor movement shortcuts:
CTRL + H/J/K/L
and the shortcuts mentioned above may conflict with existing shortcuts in software like VIM/TMUX, so it’s better to add some conditions, such as excluding terminal applications or only using them when inputting Chinese.- If you use Markdown a lot for text editing, you may need to use the
TAB
key frequently for indentation, so it’s best not to use the third group provided above, otherwise you’ll have to switch input methods to useTAB
normally.