De Mathux
Révision datée du 10 mars 2023 à 10:34 par Admin (discussion | contributions)
(diff) ← Version précédente | Voir la version actuelle (diff) | Version suivante → (diff)

Edit Macro

The registers are used both for macros and for yank and delete commands. This has some advantages.

Suppose you have recorded a few commands in register n. Then, when you run @n, you notice you did something wrong. You could try recording again, but perhaps you will make another mistake. Instead, use this trick:

  • G — Go to the end of the file.
  • o<Esc> — Create an empty line.
  • “np — Put the text from the n register. You now see the commands you typed as text in the file.
  • {edits} — Change the commands that were wrong. This is just like editing text.
  • 0 — Go to the start of the line.
  • “ny$ — Yank the corrected commands into the n register.
  • dd — Delete the scratch line.

Now you can execute the corrected commands with @n.

This trick is a great example of the Unix and Vim philosophies: If you know how to modify text, and if everything is made out of text, then you can do anything.

N.b. :From


My configuration files are hosted here. A simplified version (more re-usable) is here


  • Copy into the clipboard


  • Past from the clipboard


  • Copy/Past into/from the register "a"

"ay / "ap


  • Substitute every occurrence of '0' with incremental values:
:let @a=0 | %s/0/\=(@a+setreg('a',@a +1))/g
  • Delete all trailing whitespace (at the end of each line) with