Registers and Macros in Vim

Chemnitz Linux Days 2023—and ATIX in the thick of things! In his talk. our Senior IT Consultant Jan Bundesmann presented registers and macros in Vim. The contents in a nutshell:

▶ Registers in Vim are named clipboards
Access to a system clipboard via registers + and *
Macros allow recording of repetitive work
Macros are stored as registers

Below, you can find a few excerpts from the presentation:

Short introduction of the terminology

Clipboard CTRL + (SHIFT +)C / Copy & Paste
Primary selection

Marked text, can be inserted in a different place with the middle mouse button

Registers Internal intermediate storage in Vim

Copy and paste in Vim

{ycd} yank / change / delete until the end of the movement
yy|cc|dd yank / change / delete complete line
p|P paste before of after the cursor
{ycdp} perform yank / change / delete on the visual selection


▶ Save data in registers speichern and call up from there
▶ Named Registers

”x{ycdp} Access to Register x for the next activity
””{ycdp} Access to Default oder Unnamed Register for the next activity

48 available registers

see :help registers for reference

:, ., %
named a to z alternate file
small delete

0 to 9 last search
*, +, ~ black hole


Every action in vim is a set of key strokes.

Activities can be repeated in two ways:

Write down keyboard shortcut
Store them as macros


1. Startrecording macros x by pressing qx
2. Enter your commands
3. Stop recording by pressing q again


1. Press @x to replay macro x
2. If desired place a multiplier in front: 5@x

Modifiy macros

Vim saves macros in registers. That becomes obvious when you look at all registers (:registers).To make changes, simply overwrite the existing register:

1 “xp
2 # modify macro and visually mark it
3 “xy

This is how you create a similar macro:

1 “xp
2 # modify macro and visually mark it
3 “zy

Recursive macros

What happens when a macro x calls itself?

1. Make sure the macro is empty: qxq

2. Record macro, don’t forget to call it at the end
1 qx
3 @x
4 q

The macro will run until it produces an error.

Hier you can find the entire presentation and a video stream of the talk. Enjoy!

The following two tabs change content below.

Jan Bundesmann

Latest posts by Jan Bundesmann (see all)