I use Emacs a lot for writing — sometimes for code, sometimes for managing to-do items with org-mode, sometimes for testing the HTTP API with Restclient-mode. Emacs’ rich keyboard shortcuts allowed me to do a lot of things without leaving my hands on the main keyboard, but they also brought a different kind of annoyance: too many shortcuts made my hands tired.

The first cause of hand fatigue is that many Emacs shortcuts require holding down CTRL, which is not always easy to reach. In the case of my keyboard, the CTRL key is located at the outer end of the main keyboard area

To make it easier for the tail finger to press the CTRL key on either side, I switched the command and Control effects in macOS

When you need to hold down the CTRL key on both sides (actually the Windows icon in the photo above), you need to turn your wrist outward. This problem also exists when using VSCode, where I’m also using Emacs key mappings.

The second factor is that some of the Emacs shortcuts are too cumbersome, causing the hands to dance around the keyboard and to hit too many times. For example, the shortcuts for moving the cursor up, down, left, and right are CtrL-P, CTRL-N, CtrL-B, and CTRL-F, which are much more cumbersome than using the arrow keys directly on the keyboard. Some functions even require three sets of shortcuts, such as ctrl-c, Ctrl-x, and Ctrl-O for org-clock-out.

Is there a way to keep the efficiency of keystrokes while minimizing wrist and finger fatigue?

B: of course.

Switch to Vim shortcuts in Emacs

Since the default Emacs shortcuts aren’t easy to press, you might as well switch to Vim-style shortcuts. Similarly, to move the cursor up, down, left, and right, in Vim, you only need to click the four keys K/J/H/L, which can not only be operated with one hand, but also the four keys are exactly within the “reach” of the right hand. Other functions, such as searching within a file and saving a file, are simply pressing/and :w, which is finger-friendly compared to Emacs.

So how do you use Vim shortcuts in Emacs? The answer is to use the EVIL plugin. Install it using the package manager first

M-x package-install RET evil RET
Copy the code

Then add the code to enable evil-mode in the Emacs startup configuration file

(require 'evil)
(evil-mode 1)
Copy the code

Vim style shortcuts are now available in Emacs

customevil-mode

Simply enabling evil-mode isn’t enough to free your hands from pressing CTRL frequently, because there are many other high-frequency shortcuts in Emacs that rely on CTRL, such as Ctrl-x b to switch to other buffers, Ctrl-x Ctrl-F to open or create a new file. Even using Ctrl-C ctrl-X CtrL-O to stop a timer for a task.

Just as in data compression, shorter strings are used to replace the original strings that occur more frequently, shorter shortcut keys can be bound to frequently used features with longer shortcut keys. In evil-mode, G is a prefix key and is easy to press, so I’ve tied some heavily used functions to the prefixed shortcut key

;;; Evil-mode related key binding
(evil-global-set-key 'normal (kbd "g b") 'ido-switch-buffer)
(evil-global-set-key 'normal (kbd "g f") 'ido-find-file)
(evil-global-set-key 'normal (kbd "g o") 'org-clock-out)
(evil-global-set-key 'normal (kbd "g s") 'cuckoo-org-schedule)
(evil-global-set-key 'normal (kbd "g t") 'org-todo)
(evil-global-set-key 'normal (kbd "s") 'save-buffer)
Copy the code

Use the Vim shortcut in VSCode

VSCode is used to write Node.js projects, mainly because VSCode is a little better at writing Node.js code than Emacs js-mode, js2-mode, and Tide -mode streams. I also switched to Vim’s key mapping in VSCode and just clicked to install in the plug-in marketplace

VSCode’s Vim key mapping is actually a separate plug-in, Vim, which also supports further customization of shortcuts. Out of personal preference, I bind s to the function of saving files

// VSCode configuration file setting.json
"vim.normalModeKeyBindings": [{"before": ["s"]."commands": [
      "workbench.action.files.save"]}],Copy the code

Use BetterTouchTools to supplement evIL-mode

Although it is possible in Emacs to bind commonly used functions to a series of shorter shortcuts beginning with G, this technique does not work for all shortcuts, as too many custom shortcuts can also be a memory burden. But I won’t stop there.

If you look closely, most of the longer shortcuts are prefixed with Ctrl-C or Ctrl-X. Therefore, if you can make CtrL-C and Ctrl-X easier to press — for example, by replacing them with a single key — it also helps to reduce the burden of pressing the CTRL key with the tail finger.

To replace Ctrl-C with a single key, Emacs alone can do the same. For example, you can have F10 being pressed equivalent to ctrl-C

(defun simulate-C-c ()
  "Analog input C-C"
  (interactive)
  (setq unread-command-events (listify-key-sequence "\C-c")))
(global-set-key [f10] 'simulate-C-c)
Copy the code

The problem is it’s not combinable.

For example, pressing F10 followed by Ctrl-x is equivalent to pressing Ctrl-C ctrl-x. But if I press Ctrl-x and then F10, Emacs doesn’t convert F10 to Ctrl-C anymore, it just thinks I’m pressing the key sequence of CTRl-X F10.

What if YOU want to replace Ctrl-C with F10 but still have composability? My answer is to use BetterTouchTool. I redefined F9 through F12 with BTT

This way, when I need to type complex shortcuts with Ctrl-C or Ctrl-X, I just need to click F10 or F11 once. Easy!

Unfortunately, BTT is a macOS only software.

Afterword.

Perhaps brain-computer interfaces are the ultimate solution for finger strain relief.

Read the original