A pagan text editor

Last update: 2011-02-13.

[Get him] [Older version]

him (Heretic Vim) is a Vim script which makes it possible to use Vim primarily from Insert mode. It defines (more-or-less) intuitive keybindings for most common editing operations, and changes some of Vim's configurations to make it more usable from Insert mode (make Shift-arrows start a selection, move the current mode information to the ruler so that it doesn't hide error messages, etc.). It leaves Normal mode largely untouched, so even if you use Vim as God meant it to be used, you might benefit from him's improvements in Insert mode.

him is under development and is somewhat experimental. In particular, version 0.2 is a complete rewrite of him, so things that worked in the old version may be broken now. Use at your own risk.

him is in public domain.

Installing him

him consists of a single executable file (a Vim script with a sha-bang), so if you are on Unix, you can simply put it in a directory in your path (e.g., /usr/local/bin or ~/bin), give it execution permission (chmod a+x him), and you are done.

Alternatively, you can put him in Vim's plugins directory (~/.vim/plugins/ on Unix, create it if it doesn't exist) and rename it to him.vim. This way it will load automatically when you start Vim, but you lose the option of choosing whether you want to start plain Vim or him.

If you just want to try him out without installing it, you can open Vim and run:

:so http://inf.ufrgs.br/~vbuaraujo/sw/him/him

This requires the Netrw plugin, which comes with Vim's standard distribution.


him has a few options to control what to change and not to change of standard Vim configuration, to adapt to different terminals' ideas of what the Meta/Alt key does, and a few other things. These options are at the very beginning of him's source code, and you can change them there.

Also, when him starts, it calls the function HimPreInit() before any options are processed (so that you can still change them), and HimPostInit() after all standard keybindings are defined (so that you can override them). You can define these functions in your ~/.vimrc to control him's behavior.

The woes of Meta

The behavior of the Alt/Meta key among different terminals is an unending source of pain.

To support meta-sends-esc terminals, we have to explicitly use <Esc>a instead of <M-a> in mappings. (It is actually possible to tell Vim that <M-a> is sent as <Esc>a by the terminal, but this will make it see both Meta-a and á as <M-a>, so it doesn't work.) him's keymap functions adapt keybindings automatically depending on the value of the MetaSendsEsc option; all you have to do is set it to the appropriate value.

To make XTerm send an Esc when Meta is pressed, you can either:

This should not be an issue in gVim. (But actually is, depending on the version.)


him's keymap configuration consists of definitions and bindings.

A definition associates a command name with the key sequence that is used to accomplish that command in plain Vim. Definitions are created with the command HimDefine command-name sequence. Standard commands are given Lisp-style names (all-lowercase-with-dashes). The key sequence contains keys in the standard Vim notation. Additionally, the following strings are treated specially in the key sequence:


HimDefine  move-line-down  <n>dd<n>p
HimDefine  open-file       <f>HimOpenFile()
HimDefine  kill-backward   <i><C-u><e>

A binding is the association of a command name with a key that activates it. Bindings are created with the command HimBind modes modifiers key command-name.

modes is a string of characters indicating in which modes the binding is in effect. The mode characters are the first character in Vim's :xmap commands (n for Normal, v for Visual, i for Insert and Replace, s for Select).

modifiers is a string of characters indicating the modifiers that are active in the binding. Valid characters are C for Control, M for Meta/Alt, and S for Shift. Additionally, a z modifier means that him is to use a <M-key>-style key even when MetaSendsEsc is active, and that a key name is to be wrapped in <...> even when no modifier is present; this is necessary for arrows and other special keys. Modifier letters are case-insensitive, and other characters are ignored. It is conventional to write modifiers in uppercase, z in lowercase, and to put a dash after each modifier letter. When no modifier is present, a single dash can be used.

key is the bare key to be bound, without any modifiers, and without <...>. command-name is – guess what? – the name of the command to associate with the key.


HimBind  i     M-       /       search-forward
HimBind  in    M-S-z-   Down    focus-window-down
HimBind  i     z-       F2      open-file

There is also a lower-level command, HimMap, which is just like HimBind, except that it takes a key sequence instead of a command name as the last argument. This can be used to take advantage of him's multi-mode mappings and semi-automatic handling of Meta without having to create definitions for your commands.

The keys that can be mapped are limited by the terminal's ability to distinguish them, and by Vim's notions of the keymap. For example, you cannot map Ctrl-a and Ctrl-Shift-a to different commands, because the terminal sends the same character for both. (And Vim is unable to distinguish them either; it could work in gVim, but it doesn't, primarily just because.)

Standard commands and bindings

For now you have to look at the source code for a list of commands and bindings. As the previous section shows, however, the definition and binding commands are pretty readable, and commands tend to have descriptive names, so it is easy to figure them out. A help feature is in our five-year plans, but don't expect it to apper any time soon.

Here is the relevant source code portion, slightly beautified.

Explanations and notes

First of all, I want to thank Caio Miranda, whose insistent taunting of the way I used to use Vim made me accumulate enough rage to write the first version of him. The explosion was triggered in April 2010 (the oldest version of him that I still have is dated 2010-04-21; the first version was probably written on the previous Friday or Saturday).

For the uninitiated, Vim is a modal editor. It has two main modes, Normal and Insert. In Normal mode, keystrokes are interpreted as editing commands; for example, typing dw deletes a word. (Most commands are not as intuitive, though.) Insert mode is like other editors' only mode. The idea is that having Normal mode results in an economy of keystrokes, because for most time you don't have to hold modifier keys to type a command. This comes at the cost of having to switch modes and getting used to Vim's not-amazingly-intuitive commands.

him is a heretical attempt to turn Vim into a modeless editor. It could be argued that this misses the whole point of using Vim. However, Vim has a thousand features which make it a very good editor even if you are not an efficiency paranoid. And then, you can go back to good old Normal mode at any moment by the hit of an Esc (unless of course you have turned AvoidNormalMode on, in which case you have to type Meta-Shift-x, but it is there anyway). The alternative of using C-x 4 C-f Emacs <RET> does not strike me as particularly pleasant at the moment.

I have recently turned AvoidNormalMode on in my local installation (the default is still off, though). By keeping myself away from Normal mode I intend to gradually make him as convenient as possible to use solely from Insert mode. Hope for the best.

Suggestions, bug reports, praises and flames can be sent to the e-mail address indicated at the main page.

This document is in public domain.