Finger pain, write some code to ease it

Time:2020-11-6

I often use Emacs for writing – sometimes writing code, sometimes using org mode to manage to-do lists, and sometimes using restclient mode to test the HTTP API. Emacs’s rich shortcut keys allow me to do a lot of things without leaving the main keyboard area, but it also brings a different kind of trouble: pressing too many shortcut keys makes my hands tired.

The first factor causing hand fatigue is that many shortcut keys of Emacs need to be pressed and heldctrlTo use, andctrlIt’s not always easy to press. Take my keyboard, for example,ctrlThe keys are located on the outermost side of the main keyboard area

Finger pain, write some code to ease it

To make it easier for the tail finger to press on both sidesctrlKey, I switched in Mac OScommandandcontrolKey effect

Finger pain, write some code to ease it

When you need to press thectrlWhen you press the windows Icon key in the picture above, you need to turn your wrist out. This problem also exists when using vscode, because I also use Emacs key mapping in vscode.

The second factor is that some of Emacs’s shortcut keys are too cumbersome, resulting in the use of both hands like dancing on the keyboard to press everywhere, too many times to hit. For example, the shortcut keys for moving the cursor up, down, left and right arectrl-pctrl-nctrl-b, andctrl-fThis is much more troublesome than using the arrow keys on the keyboard. Some functions even need to press three groups of shortcut keys, such asorg-clock-outPress firstctrl-c, and then pressctrl-x, and finally pressctrl-o

Is there any way to keep the shortcut key efficient and minimize wrist and finger fatigue caused by keystrokes?

Of course.

Using VIM shortcut key in Emacs

Since the default shortcut key of Emacs is not easy to press, you may as well change to VIM style shortcut key. Again, move the cursor up, down, left and right. In VIM, you just clickk/j/h/lThese four keys can be used, not only can be operated by one hand, but also the four keys are just “within reach” of the right hand. Other functions, such as searching in files, saving files, etc., can also be done by pressing/and:wThat’s a lot more “finger friendly” than Emacs.

So how to use VIM shortcut key in Emacs? The answer is yesevilplug-in unit. Install it with the package manager first

M-x package-install RET evil RET

Then add enable in Emacs’ startup configuration fileevil-modeCode for

(require 'evil)
(evil-mode 1)

Now you can use VIM style shortcut keys in Emacs

Finger pain, write some code to ease it

customizedevil-mode

It’s simply enabledevil-modeIt’s not enough to push your hands from frequent pressctrlBecause there are many other high-frequency shortcut keys in Emacsctrl, e.gctrl-x bTo switch to other buffers and usectrl-x ctrl-fTo open or create a new file, or even usectrl-c ctrl-x ctrl-oTo stop a task timer.

Just as in data compression, a shorter string is used to replace the original string with a higher frequency of occurrence. For functions with high frequency and long shortcut keys, shorter shortcut keys can be bound to them. stayevil-modeMedium,gIt’s a prefix key and it’s easy to press, so I’ve bound some heavily used functions to the shortcut keys prefixed with it

;;; 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)

Use VIM’s shortcut key in vscode

The tool for moving bricks is vscode, which is used to write Node.js The main reason is that vscode is writing Node.js The code is better than Emacsjs-modejs2-mode, andtide-modeIt’s better to use it. In vscode, I also use VIM’s key mapping instead, just click Install in the plug-in market

Finger pain, write some code to ease it

Vscode’s VIM key mapping is actually a stand-alone plug-inVimIt also supports further customization of shortcut keys. For personal preference, I putsBind to save file function

//Configuration file for vscode setting.json
"vim.normalModeKeyBindings": [
  {
    "before": ["s"],
    "commands": [
      "workbench.action.files.save"
    ]
  }
],

Complement evil mode with better touch tools

Although in Emacs, you can bind common functions to a series ofgThe short shortcut key at the beginning, but this move can not be used to deal with all the shortcut keys, because too many custom shortcut keys will also bring a burden on memory. But I’m not going to stop there.

If you look closely, you will find that most of the longer shortcut keys arectrl-corctrl-xAs a prefix. Therefore, if we can makectrl-candctrl-xIt’s easier to press – for example, replacing it with a single button – also helps to reduce tail finger pressctrlKey burden.

Use a single key insteadctrl-cEmacs alone can do it. For example, you can makeF10Being pressed is equivalent to pressingctrl-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)

The problem is that it’s not composable.

For example, first pressF10Press againctrl-x, which is equivalent to pressingctrl-c ctrl-x。 But if you pressctrl-xPress againF10, Emacs will notF10Convert toctrl-cIt will only think that I pressed yesctrl-x F10Key sequence of.

BothF10replacectrl-cWhat to do with composability? My answer is to useBetterTouchTool。 I use BTT toF9reachF12It’s all redefined

Finger pain, write some code to ease it

In this way, when I need to input complex, containingctrl-corctrl-xYou only need to click onceF10orF11That’s enough. It’s easy!

Unfortunately, BTT is a Mac OS only software.

Postscript

Maybe BCI is the ultimate solution to relieve finger strain.

Read the original