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 heldctrl
To use, andctrl
It’s not always easy to press. Take my keyboard, for example,ctrl
The keys are located on the outermost side of the main keyboard area
To make it easier for the tail finger to press on both sidesctrl
Key, I switched in Mac OScommand
andcontrol
Key effect
When you need to press thectrl
When 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-p
、ctrl-n
、ctrl-b
, andctrl-f
This 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-out
Press 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/l
These 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:w
That’s a lot more “finger friendly” than Emacs.
So how to use VIM shortcut key in Emacs? The answer is yesevil
plug-in unit. Install it with the package manager first
M-x package-install RET evil RET
Then add enable in Emacs’ startup configuration fileevil-mode
Code for
(require 'evil)
(evil-mode 1)
Now you can use VIM style shortcut keys in Emacs
customizedevil-mode
It’s simply enabledevil-mode
It’s not enough to push your hands from frequent pressctrl
Because there are many other high-frequency shortcut keys in Emacsctrl
, e.gctrl-x b
To switch to other buffers and usectrl-x ctrl-f
To open or create a new file, or even usectrl-c ctrl-x ctrl-o
To 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-mode
Medium,g
It’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-mode
、js2-mode
, andtide-mode
It’s better to use it. In vscode, I also use VIM’s key mapping instead, just click Install in the plug-in market
Vscode’s VIM key mapping is actually a stand-alone plug-inVimIt also supports further customization of shortcut keys. For personal preference, I puts
Bind 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 ofg
The 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-c
orctrl-x
As a prefix. Therefore, if we can makectrl-c
andctrl-x
It’s easier to press – for example, replacing it with a single button – also helps to reduce tail finger pressctrl
Key burden.
Use a single key insteadctrl-c
Emacs alone can do it. For example, you can makeF10
Being 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 pressF10
Press againctrl-x
, which is equivalent to pressingctrl-c ctrl-x
。 But if you pressctrl-x
Press againF10
, Emacs will notF10
Convert toctrl-c
It will only think that I pressed yesctrl-x F10
Key sequence of.
BothF10
replacectrl-c
What to do with composability? My answer is to useBetterTouchTool。 I use BTT toF9
reachF12
It’s all redefined
In this way, when I need to input complex, containingctrl-c
orctrl-x
You only need to click onceF10
orF11
That’s enough. It’s easy!
Unfortunately, BTT is a Mac OS only software.
Postscript
Maybe BCI is the ultimate solution to relieve finger strain.