NeoVim - Show macro recording when cmdheight is set to 0
When cmdheight
is set to 0 in NeoVim, the indication (recording @x
) for macro recording won’t pop up anymore. This can be problematic if q
is accidentally pressed, causing NeoVim to freak out at times.
I’ve found two solutions to this:
Display the register returned from the
vim.fn.reg_recording()
call on the statusline. While this works great, it needs to be added to the statusline and can become problematic when using statusline plugins.I recall seeing
RecordingEnter
andRecordingLeave
events in theautocmd
section of the Vim help. Utilizing these, I was able to set triggers to togglecmdheight
when recording macros.
Here’s the code to set these autocmds:
local cmdheight = vim.api.nvim_get_option_value('cmdheight', {})
if cmdheight == 0 then
vim.api.nvim_create_autocmd({'RecordingEnter'}, {
command = "set cmdheight=1",
desc = "Show cmdline when recording macro"
})
vim.api.nvim_create_autocmd({'RecordingLeave'}, {
command = "set cmdheight=0",
desc = "Remove cmdline when macro recording ended"
})
end