The editor hotkeys hiding in plain sight
If you’ve ever used the vim or emacs family of editors, you’ll know they each contain hundreds or even thousands of commands bound to different keys. What many people don’t know is that these keybindings are also used in dozens of everyday applications - command line tools, text inputs, and even web applications. Let’s explore where vim or emacs knowledge can be used in your everyday tools.
Vim vs emacs
The editor war is a long-running, light-hearted battle between the vi-style of editing and the emacs style of editing.
The vi-style makes use of ‘modes’, allowing for concise, composable commands. For example, to swap the current line and the line below, then save the current file, you would:
- Make sure you’re in ‘normal mode’ by pressing
ddto delete the current line;
pto paste what you just deleted after the cursor;
:wand hit the
<return>key to save the file.
The emacs style is ‘modeless’ (like most editing styles), using modifier keys such as
Alt) combined with a character for different commands.
To accomplish the same example in emacs, you would:
- Move down a line with
C-tto execute the command
C-sto save the file.
Shells and readline
Out of the box both
zsh support emacs-style cursor navigation:
C-e- move to the start and end of the line;
C-b- move forward and backward a character;
C-p- move forwards and backwards through your command history;
C-h- delete the previous character.
This is also supported by tools that use
readline, such as the
node interactive REPLs.
If you prefer vim style, you can also change the input mode in
set editing-mode vi # use vim style readline editing set show-mode-in-prompt # show an indicator when in insert / normal mode
With vi-mode enabled, you can press escape at any point to change to normal mode, where most of the composable vim commands are available.
Both bash and zsh also have the emacs hotkey
C-x C-e to open the current command in
Less, man, and other pagers
Pagers such as
git log, etc, all support vim keys.
I like to scroll through man pages using
C-u and search for a phrase with
There are many commandline applications specifically designed with vim keys in mind:
- tig, a git client;
- ranger, a file manager;
- tmux, a terminal multiplexer;
- ncmpcpp, a client to the music player daemon.
See also the Big Pile of Vim-like software.
If you’re on Mac OS, most text input boxes support emacs-style navigation.
C-h all work, as well as
C-B to highlight text.
In a browser address bar you can additionally use
C-p to navigate between different options in the search bar.
Web sites and applications
Even some web applications have familiar hotkeys:
- The Gmail interface has a large amount of hotkeys, including
kto move between emails,
xto select an email,
eto archive, and
#to delete. Make sure keyboard shortcuts are enabled in your gmail settings, then press
?to see all the available options.
- DuckDuckGo also uses
kto navigate between search results,
oto open a link, and
/to focus the search box.
- Some of the Github hotkeys have parallels with vim, including
/to search, the
gprefix to go to various places, and
kto move things up and down on certain pages.
Keyboard powered web browsing
To go even further, web browsers can be powered entirely by vim keys! Firefox and Chrome have the Tridactyl and Vimium extensions, and luakit is a standalone browser that uses vim keys for navigation.
It’s possible to fully embrace the vim way of navigating the web with these extensions, almost completely removing the need for a mouse.
It’s tempting to pick one side in the editor war and ignore the other, but I feel that having the basics mastered in both editors helps you tremendously when using different unix tools and applications.
Once you become proficient with both styles, you’ll start to notice vim and emacs shortcuts in many applications you use every day. You’ll start to feel the pain when your application doesn’t have these hotkeys built in, and want to seek out alternatives that do!
To get started, simply type
emacs -Q -f help-with-tutorial in your unix shell.