vim Record and replay action (macros)


Example

with q command we could simplify a lot of tedious work in vim.

example 1. generate array sequence (1 to 20).

STEP 1. press i to enter insert mode, input 1

1

STEP 2. Record following action: "append the last number to the next line, and increment the number"

  1. type esc to exit input mode
  2. type qa to enter record mode, using buffer a
  3. type yy and p to copy current line and paste it as the next line
  4. type ctrl + a to increment number
  5. type q again to finish record
1
2

STEP 3. Replay action 18 times.

type 18@a to replay action 3 and action 4 in step 2.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20