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 registerst 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

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


Recording1. Startrecording macros x by pressingqx
2. Enter your commands
3. Stop recording by pressing q again


Replay1. 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 macrosWhat 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
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! Enjoy!

The following two tabs change content below.

Jan Bundesmann

Latest posts by Jan Bundesmann (see all)