Vim

2024-07-14

1. Simulating Vim on the Page

ctrl-s is a common convention for representing chordal commands. It means "Press the Control key and the s key at the same time." But this convention isn’t well suited to describing Vim’s modal command set.

1.1. Playing Melodies

In Normal mode, we compose commands by typing one or more keystrokes in sequence. There commands appear as follows:

Notation Meaning

x

Press x once

dw

In sequence, pres d, then w

dap

In sequence, pres d, a, then p

Most of these sequences involve two or three keystrokes, but some are longer. Deciphering the meaning of Vim’s Normal mode command sequences can be challenging, but you’ll get better at it with practice.

1.2. Playing Chords

When you see a keystroke such as <C-p>, it doesn’t mean "Press <, then C, then -, and so on." The <C-p> notation is equivalent to Ctrl-p, which means "Press the Ctrl and p keys at the same time" Some of Vim’s commands are formed by combining chords and keystrokes in sequence, and this notation handles them well. Consider these examples:

Notation Meaning

<C-n>

Press <Ctrl> and n at the same time

g<C-]>

Press g, followed by <Ctrl> and ] at the same time

<C-r>0

Press <Ctrl> and r at the same tile, then 0

<C-w><C-=>

Press <Ctrl> and w at the same time, then <Ctrl> and = at the same time

1.3. Placeholders

Some commands must be followed by a particular kind of keystroke, while other command can be followed by any key on the keyboard. I use curly braces to denote the set of valid keystrokes that can follow a command.

Here are some examples:

Notation Meaning

f{char}

Press f, followed by any other character

`{a-z}

Press `, followed by any lowercase letter

m{a-zA-Z}

Press m, followed by any lowercase or upper case letter

d{motion}

Press d, followed by any motion command

<C-r>{register}

Press <Ctrl> and r at the same time, followed by the address of a register

1.4. Showing Special Keys

Some keys are called by name. This table shows a selection of them:

Notation Meaning

<Esc>

Press the Escape key

<CR>

Press the carriage return key (aka <Enter>)

<Ctrl>

Press the Control key

<Tab>

Press the Tab key

<Shift>

Press the Shift key

<S-Tab>

Press the <Shift> and <Tab> key at the same time

<Up>

Press the up-arrow key

<Down>

Press the down-arrow key

 

Press the space bar

Note that the space bar is represented as  . This could be combined with the f{char} command to form .