Vim 9 cheatsheet

Vim 9: Macros and settings

10 common Vim 9 tasks.

Record a macro

Record keystrokes into register a. Press q again to stop recording.

qa  ...  q

Play a macro

Run register a. Prefix a count to repeat it, such as 10@a.

@a

Repeat the last macro

Run the most recently used macro again.

@@

Show line numbers

Show the line number beside each line.

:set number

Show relative line numbers

Show distances from the cursor line, which helps with motions like 5j.

:set relativenumber

Use four spaces for indentation

Insert spaces when you press Tab.

:set expandtab tabstop=4 shiftwidth=4

Paste without auto-indent

Stop Vim re-indenting pasted text. Turn it off again with :set nopaste.

:set paste

Run a shell command

Run a command and show its output.

:!ls -l

Insert a command's output

Read the output of a command into the buffer below the cursor.

:r !date

Open help

Open the built-in help for a topic.

:help :substitute

Was this page helpful?