Vim Macros are awesome. But it's hard to get it right on the first try.
-- dohsimpson 2015
I couldn't agree more, so I tried his plugin vim-macroeditor, and it was almost perfect.
It's a tiny plugin, 27 lines of VimScript, so it's easy to edit. I've rewritten it in Lua and modified the following:
- Now you can edit any register, not just macros
- Though the best use is for editing macros, editing other types of registers is basically the same thing, so just allow it
- The command is
:R[egisterEdit]- Best to use with just
:R
- Best to use with just
- Checks that argument is a valid register
- No warnings when editing a register that wasn't already set
- Allows more than one window open at the same time
- Window shows register name in statusline
- Window height is set based on number of lines in register
- Always splits window below
Big thanks to dohsimpson for sharing the original plugin.
With lazy.nvim:
{
'tuurep/registereditor',
}Start editing a register with :R <register>
Update <register> contents with :wq
Or discard changes with :q!
When you need to insert special characters like <Esc> (displayed as ^[) in a macro, press Ctrl + v in insert mode followed by Esc
Newlines in registers are stored as ^J (see :h NL-used-for-Nul). This causes an actual Ctrl + j keypress in a macro.
That's why macros should be written only on the first line of the registereditor buffer with no empty lines after.
When a newline at the end of the register is desired, the registereditor buffer should end in an empty line.
This plugin is in essence a less cumbersome alternative to one of the following methods:
Example register q
-
On the command line:
:let @q = "<C-r>q"- Register
qcontents are pasted on commandline for editing
-
Temporarily pasting to a buffer for editing:
"qp- Edit inside buffer
- Yank it back using something like:
"qy. . ."qd. . .