Linux Distros and Termux.
When updating termux-setup.sh
to make it pass shellcheck, I revisited the linked guide Termux 高级终端安装使用配置教程 I referred to years ago and was surprised to find out that it’s still being updated.
There is a customize extra key section in the article that I’m not aware of so I spent some time doing that, hence the post.
If you can’t read Chinese, the related section is located in Touch Keyboard on Termux Wiki. You’ll need the support keys list as many key entires are strings like QUOTE
for "
and BACKSLASH
(or a silly '\\\\'
, but backslash
won’t work) for \
.
Alternatively, you can check ExtraKeysConstants.java
for a complete list although the documentation said it’s defined in ExtraKeysView.java
.
You can edit "$HOME"/.termux/termux.properties
to customize it, and remember to run termux-reload-settings
to apply the changes, otherwise it would only work after you open a new session or reopen the app.
Extra keys are enable by default since 2020 so chances are you won’t need to customize it if the following makes you satisfied already.
The default settings in termux.property
:
extra-keys = [ \
['ESC','|','/','HOME','UP','END','PGUP','DEL'], \
['TAB','CTRL','ALT','LEFT','DOWN','RIGHT','PGDN','BKSP'] \
]
Quoted from Termux Wiki:
In Termux v0.95 extra keys configuration was extended with configurable popups. Popups keys can be triggered by swiping up on the respective keys.
The syntax:
{key: KEY, popup: POPUP_KEY}
{key: KEY, popup: {macro: 'KEY COMBINATION', display: 'Key combo'}}
And the official example (which is also included in termux.property
for your reference):
extra-keys = [[ \
{key: ESC, popup: {macro: "CTRL d", display: "tmux exit"}}, \
{key: CTRL, popup: {macro: "CTRL f BKSP", display: "tmux ←"}}, \
{key: ALT, popup: {macro: "CTRL f TAB", display: "tmux →"}}, \
{key: TAB, popup: {macro: "ALT a", display: A-a}}, \
{key: LEFT, popup: HOME}, \
{key: DOWN, popup: PGDN}, \
{key: UP, popup: PGUP}, \
{key: RIGHT, popup: END}, \
{macro: "ALT j", display: A-j, popup: {macro: "ALT g", display: A-g}}, \
{key: KEYBOARD, popup: {macro: "CTRL d", display: exit}} \
]]
I think there is something wrong with it as running termux-reload-settings
after setting this would throw a JSON parsing error. Anyway, I combine all the configuration above and create my own.
Let’s have a simple one first:
extra-keys = [['ESC','|','BACKSLASH','`','UP','QUOTE','APOSTROPHE'], \
['TAB','CTRL','ALT','~','LEFT','DOWN','RIGHT','ENTER']]
Every []
stands for a line of buttons, so we would get two rows using the settings above.
~
is the literal ~
, meaning $HOME
in shells. I think all other keys are evident.
Now we have this (j/k, don’t worry, I’ll explain it in #Explanation):
extra-keys = [[ \
{key: ESC, popup: {macro: ": q ENTER", display: "vim quit"}}, \
{key: '|', popup: '-'}, \
{key: BACKSLASH, popup: '/'}, \
{key: '`', popup: {macro: "CTRL SPACE %", display: "tmux vert"}}, \
{key: UP, popup: {macro: "CTRL u", display: "UP PG"}}, \
{key: QUOTE, popup: {macro: "CTRL SPACE QUOTE", display: "tmux land"}}, \
{key: APOSTROPHE}, \
{key: PGUP, popup: HOME], [\
{key: TAB}, \
{key: CTRL, popup: {macro: ": w ENTER", display: "vim save"}}, \
{key: ALT, popup: {macro: ": wq ENTER", display: "vim wq"}}, \
{key: LEFT, popup: {macro: "CTRL a", display: "HOME"}}}, \
{key: DOWN, popup: {macro: "CTRL d", display: "DN PG"}}, \
{key: RIGHT, popup: {macro: "CTRL e", display: "END"}}, \
{key: '~', popup: {macro: "QUOTE $ H O M E QUOTE", display: "$HOME"}}, \
{key: PGDN, popup: PGDN} \
]]
{key: ESC, popup: {macro: ": q ENTER", display: "vim quit"}}, \
{key: CTRL, popup: {macro: ": w ENTER", display: "vim save"}}, \
{key: ALT, popup: {macro: ": wq ENTER", display: "vim wq"}}
Although I know how to exit Vim and use it everyday, it’s really cumbersome to do it in virtual keyboard. BTW I tried Emacs a few times, and every time it ended up feeling like a monster I can’t control, but god mode and org mode are really cool! It would be a bit pointless if I switch to Emacs and settle on evil mode. Also, I tried Neovim and Vim plugins several times, there are always minor issues preventing me from completion. Maybe I’ll try these another time soon™.
Also, I don’t want to press two keys to move half page forward/backward. Instead, I scroll the screen directly, or swipe up extra keys:
{key: UP, popup: {macro: "CTRL u", display: "UP PG"}}, \
{key: DOWN, popup: {macro: "CTRL d", display: "DN PG"}}
{key: '`', popup: {macro: "CTRL SPACE %", display: "tmux vert"}}, \
{key: QUOTE, popup: {macro: "CTRL SPACE QUOTE", display: "tmux land"}}
Note that I use ohmytmux and change the command prefix (<prefix
) to <ctrl> + <space>
. I think by default <prefix>
would be <ctrl> + a
for ohmytmux and <ctrl> + b
for vanilla tmux.
{key: LEFT, popup: {macro: "CTRL a", display: "HOME"}}}, \
{key: RIGHT, popup: {macro: "CTRL e", display: "END"}}, \
{key: '~', popup: {macro: "QUOTE $ H O M E QUOTE", display: "$HOME"}}, \
The first two are common hotkeys in Bash, and is just in the very beginning of The Art of Command Line which I highly recommend reading. The last one is used when I write scripts, as relative path won’t work sometimes. Since I mentioned The Art of Command Line, I also spent a lot of time reading Bash Strict Mode, pure-sh-bible and pure-bash-bible when learning Bash scripting. They are all extremely useful materials and worth checking every once in a while.
The remaining ones are quite evident to me so no explanation on these:
{key: '|', popup: '-'}, \
{key: BACKSLASH, popup: '/'}, \
{key: APOSTROPHE}, \
{key: PGUP, popup: HOME}, \
{key: TAB}, \
{key: PGDN, popup: END}
First, you need to really use it. Tools are just tools, they can make you seem 100x more productive, but only when you are producing something.
Second, key strokes in macros are sent in a sequence, NOT simultaneously. That’s how I understand why the following configuration does not work:
{key: LEFT, popup: {macro: "CTRL SPACE LEFT", display: "tmux ←"}},
{key: RIGHT, popup: {macro: "CTRL SPACE RIGHT", display: "tmux →"}}
Or maybe I just misspell it somehow, as I notice the default advanced has a similar macro.
I’m (again) back to the No Man’s Land I mentioned in Background so many of my plans have to be postponed. I don’t know why I’m writing this postscript since it means nothing to you, but anyway just write it to make me feel connected with the world as there is literally no entertainment in a rural (read: isolated) land besides gossiping and bragging which I’m totally sick of.
Sine īrā et studiō