Vi mode for everything

When it comes to editing text documents, many people especially programmers have a strong opinion which text editor is the best. I also have such an opinion. For quite some time I have been using vi or vim as my text editor of choice. Vim is quite different from most other editors in its usage. In fact, there's even a lot of jokes along the lines of:

How do you generate strong passwords? Tell a user who hasn't used it before, to exit vim.

While it is certainly true that vim takes some time getting used to, my editing speed has increased tremendously since I started using it. In fact, it increased so much, that I soon started missing vim keybindings in other software. But for many other software, there are solutions.

For example, you can get vi extensions for many browsers, that allow you to browse the web largely without a mouse, by using vi keybindings. I am currently using Vimium on Chromium/Chrome and VimFx on Firefox, but there are several others to choose from. All of the extensions have different strengths and drawbacks. There are also often vi keybinding settings or add-ons for different editing tools or other software, but that is not what I want to get into today.

In addition to using a text editor such as vim, I also do not use a graphical file browser, when working at my computer. Instead, I prefer working on the console. It makes me keep more organised and with a little bit of shell coding, many tasks can be solved very quickly and elegantly. As a side note, I am using a Linux system. I have no idea if or how the following also applies to Windows, but it will probably work on Macs as well.

When using the console, you often have to type commands. Naturally, you also often have to correct them, or you may want to repeat commands from a while ago. Thus it was a very happy moment for me when I learned that there was a vi mode for the shell. This allows me to edit already entered commands, and to generally use vi keys in order to use the console faster and eliminating a lot of hand movements.

You can enable simply by typing

set -o vi 

in your console. Of course, you can also add the line to your .bashrc, .profile or wherever you like to configure your console.

However, there is also a more powerful way to get vi key bindings for your shell. In addition to turning on vi mode in the shell, it also enables vi mode for all applications that use readline as their input. Thus, most interactive console tools will allow you to use your favourite vi bindings as well! You can achieve this by adding the following lines to your ~/.inputrc file. 

set keymap vi 
set editing-mode vi

I wanted to write about this, because I often configure a system but then forget about how it is done or how and why this works. 

Update: 2017-05-24
On a related note, Stack Overflow just published a quite funny and interesting article about how developers need help exiting Vim.