sponsor Vim development Vim logo Vim Book Ad

macro-line : Keep macros as readable lines inside the files they work on, and load them back

 script karma  Rating 0/0, Downloaded by 4  Comments, bugs, improvements  Vim wiki

created by
Illia Bobyr
 
script type
utility
 
description
Some macros only make sense for one file, or a group of files: reformat this
table, renumber those headings.  They are worth keeping beyond the current
session, together with a note on how to use them.  But a recorded register is
full of control characters and terminal key codes, so pasting it into a file
does not work well.

This plugin writes a register into the file in <> key notation (using
keytrans()), as a readable and sourceable line, and reads it back:

    Turn a "Name: value" line into a table row:
    `let @t = "I| \<Esc>f:r|A |\<Esc>j"`

The macro may sit anywhere on a line: in a code comment, in a Markdown list
item, next to its explanation.  New lines are wrapped to suit the file: in
'commentstring' for code, in inline code for Markdown, as is for plain text.

Loading only reads the "..." string, as a string; nothing from the file is
executed.

Commands (mappings in parentheses, "x before them picks a register):

  :MacroPut[!] [x]        put register x below/above the cursor  (<Leader>mp / <Leader>mP)
  :[range]MacroLoad [x]   load the macros on these lines         (<Leader>ml, also Visual)
  :MacroUpdate [x]        rewrite the line after re-recording    (<Leader>mu)

:%MacroLoad loads every macro in the file.  Default mappings are only created
when the keys are free, and can be changed or disabled; <Plug> mappings are
provided.  See :help macro-line.

Requires keytrans(): Vim 9.0+ or Neovim 0.8+.
License: MIT.
 
install details
Unzip into ~/.vim (or ~/vimfiles on Windows), or into a package directory
such as ~/.vim/pack/plugins/start/macro-line, then run
  :helptags ~/.vim/doc
(or :helptags on the package's doc directory).
 

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
vim-macro-line-1.1.zip 1.1 2026-11-17 9.0 Illia Bobyr Documentation fix: :MacroPut without a register saves g:macro_line_register,
else the register last recorded into on Neovim (reg_recorded()), else "q".
On Vim the default is "q".  No functional changes.
vim-macro-line-1.0.zip 1.0 2026-11-17 9.0 Illia Bobyr Initial upload
ip used for rating: 216.73.216.218

Questions about Vim should go to the maillist. Help Uganda.     Vim at Github