w3m and touchscreen

Termux emulates a Linux terminal on Android. After installing Termux on your smartphone, run packages install coreutils to launch the Linux terminal experience. It does not require rooting.

Among Linux command-line apps directly available for Termux, there is the w3m browser. Out of the box, w3m does not react to touch very well. For example, you cannot drag the page line by line. Instead, the touch scroll drags the cursor, and when the cursor reaches the bottom edge, the page jumps half screen width.

To fix this, install Nano the text editor for Termux, and then start it with nano .w3m/keymap. Then enter the following.

keymap UP NULL
keymap DOWN NULL
keymap UP DOWN
keymap DOWN UP

The first two lines are to ensure that the defaults get nulled and the last two lines are to ensure that the “up” gesture (and also the “up” button on the keyboard, if your keyboard has it) would scroll so that lines vanish at the upper edge of the screen and new lines, if available, appear at the lower edge, and vice versa for the “down” gesture (and the “down” button on the keyboard), just as expected on Android. To have these settings the other way would result in a Mac-like scroll.

These settings ignore the cursor in w3m. If you think you need to move the cursor around with precision, or any other additional keybinds, feel free to add more settings in the .w3m/keymap file.

Leave a Reply

Your email address will not be published. Required fields are marked *