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 der vollständigen Zeile
p|P paste vor oder nach der Cursorposition
{ycdp} perform yank / change / delete on the visual selection

Registers

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

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

“presentation”>48 available registers

see :help registers for reference
unnamed
read-only
%
named a to z alternate file
small delete
expression
numbered
0 to 9 last search
selection
*, +, ~ black hole
_

Macros

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


Recording

1. Startrecordingmacros x by pressingqx
2. Enter your commands
3. Stop recording by pressing q again


Replay

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


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
2 <do< span=””> SOMETHING></do<>
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!

+ posts