Skip to content

00dani/livemacros.vim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

livemacros.vim

livemacros.vim allows you to write @-style Vim macros in a regular buffer, either as an alternative to manually recording them with q or as a way to edit a macro you've already recorded. Your macro will be run automatically as you go, providing a live preview of its effect.

The plugin is fully compatible with Vim 9+, Neovim, and with older Vims compiled with if_ruby. I highly recommend using either Vim 9+ or Neovim if possible, since Vim's Ruby bindings are unpopular and aren't especially well-maintained.

Install

Add 00dani/livemacros.vim to your Vim plugins in whatever way you prefer. For example, with vim-plug:

Plug '00dani/livemacros.vim'

Or with minpac:

call minpac#add('00dani/livemacros.vim')

Or if you're a Neovim user, with lazy.nvim:

{'00dani/livemacros.vim'}

Usage

Get started by running the :Livemacro command.

:Livemacro

A --livemacro-- window will open at the bottom of your tab page. Start typing your macro into this window; whenever you leave Insert mode or apply a Normal mode command to the --livemacro-- buffer, it'll automatically be applied to the buffer you started with, giving you a realtime preview of your macro's result.

Once you're happy with your macro definition, simply close the livemacro window and livemacros.vim will automatically clean itself up, saving your macro for use with the @ command. If you change your mind, you can cancel a livemacro sesssion and restore the original contents of your macro register with :LivemacroCancel.

It's recommended that you set up a mapping to record livemacros. livemacros.vim won't do this by itself, but you can make it do so with a call like this in your ~/.vimrc:

call livemacros#setup#map('Q')

Then you can record a livemacro into register x using Qx. (Q is a good choice since it's extremely similar to q, and honestly who uses Ex-mode anyway? Still, this is optional just-in-case you do in fact use Ex mode.)

If you're a Neovim user, you can also ask livemacros.vim to generate mappings for you from Lua:

require 'livemacros'.setup {map = 'Q'}
-- or if you use lazy.nvim
{'00dani/livemacros.vim', opts = {map = 'Q'}}

About Macro Registers

By default, livemacros.vim will use the unnamed register "" to store your in-progress macro. This is probably not what you want in most cases, since the unnamed register changes so often. In particular, commands such as d and y always update the unnamed register, in addition to any register you've asked them to use with the " prefix.

Thus, it's recommended to use the named registers "a to "z for your macros instead, since these registers only change when you specifically ask them to change.

You can change the register used by a livemacro by passing an argument to the :Livemacro command:

:Livemacro l
" store in register l

Or by using the " command prefix:

"q:Livemacro
" store in register q

Or, if you used livemacros#setup#map():

Qp
" store in register p

TODO

  • Decide on sane behaviour for the uppercase registers "A to "Z. Right now they behave super weirdly if used.

About

Write Vim macros in a buffer with live preview

Resources

Stars

Watchers

Forks

Packages

No packages published