GithubHelp home page GithubHelp logo

nvim-recorder's Introduction

nvim-recorder πŸ“Ή

badge

Enhance the usage of macros in Neovim.

Features

  • Simplified controls: One key to start and stop recording, a second key for playing the macro. Instead of qa … q @a @@, you just do q … q Q Q.1
  • Macro Breakpoints for easier debugging of macros. Breakpoints can also be set after the recording and are automatically ignored when triggering a macro with a count.
  • Status line components: Particularly useful if you use cmdheight=0 where the recording status is not visible.
  • Macro-to-Mapping: Copy a macro, so you can save it as a mapping.
  • Various quality-of-life features: notifications with macro content, the ability to cancel a recording, a command to edit macros,
  • Performance Optimizations for large macros: When the macro is triggered with a high count, temporarily enable some performance improvements.
  • Uses up-to-date nvim features like vim.notify. This means you can get confirmation notices with plugins like nvim-notify.

Setup

Installation

-- lazy.nvim
{
	"chrisgrieser/nvim-recorder",
	dependencies = "rcarriga/nvim-notify", -- optional
	opts = {}, -- required even with default settings, since it calls `setup()`
},

-- packer
use {
	"chrisgrieser/nvim-recorder",
	requires = "rcarriga/nvim-notify", -- optional
	config = function() require("recorder").setup() end,
}

Calling setup() (or lazy's opts) is required.

Configuration

-- default values
require("recorder").setup {
	-- Named registers where macros are saved (single lowercase letters only).
	-- The first register is the default register used as macro-slot after
	-- startup.
	slots = { "a", "b" },

	mapping = {
		startStopRecording = "q",
		playMacro = "Q",
		switchSlot = "<C-q>",
		editMacro = "cq",
		deleteAllMacros = "dq",
		yankMacro = "yq",
		-- ⚠️ this should be a string you don't use in insert mode during a macro
		addBreakPoint = "##",
	},

	-- Clears all macros-slots on startup.
	clear = false,

	-- Log level used for any notification, mostly relevant for nvim-notify.
	-- (Note that by default, nvim-notify does not show the levels `trace` & `debug`.)
	logLevel = vim.log.levels.INFO,

	-- If enabled, only critical notifications are sent.
	-- If you do not use a plugin like nvim-notify, set this to `true`
	-- to remove otherwise annoying messages.
	lessNotifications = false,

	-- Use nerdfont icons in the status bar components and keymap descriptions
	useNerdfontIcons = true,

	-- Performance optimzations for macros with high count. When `playMacro` is
	-- triggered with a count higher than the threshold, nvim-recorder
	-- temporarily changes changes some settings for the duration of the macro.
	performanceOpts = {
		countThreshold = 100,
		lazyredraw = true, -- enable lazyredraw (see `:h lazyredraw`)
		noSystemClipboard = true, -- remove `+`/`*` from clipboard option
		autocmdEventsIgnore = { -- temporarily ignore these autocmd events
			"TextChangedI",
			"TextChanged",
			"InsertLeave",
			"InsertEnter",
			"InsertCharPre",
		},
	},

	-- [experimental] partially share keymaps with nvim-dap.
	-- (See README for further explanations.)
	dapSharedKeymaps = false,
}

If you want to handle multiple macros or use cmdheight=0, it is recommended to also set up the status line components:

Status Line Components

-- Indicates whether you are currently recording. Useful if you are using
-- `cmdheight=0`, where recording-status is not visible.
require("recorder").recordingStatus()

-- Displays non-empty macro-slots (registers) and indicates the selected ones.
-- Only displayed when *not* recording. Slots with breakpoints get an extra `#`.
require("recorder").displaySlots()

Tip

Use with the config clear = true to see recordings you made this session.

Example for adding the status line components to lualine:

lualine_y = {
	{ require("recorder").displaySlots },
},
lualine_z = {
	{ require("recorder").recordingStatus },
},

Tip

Put the components in different status line segments, so they have a different color, making the recording status more distinguishable from saved recordings

Basic Usage

  • startStopRecording: Starts recording to the current macro slot (so you do not need to specify a register). Press again to end the recording.
  • playMacro: Plays the macro in the current slot (without the need to specify a register).
  • switchSlot: Cycles through the registers you specified in the configuration. Also show a notification with the slot and its content. (The currently selected slot can be seen in the status line component.)
  • editMacro: Edit the macro recorded in the active slot. (Be aware that these are the keystrokes in "encoded" form.)
  • yankMacro: Copies the current macro in decoded form that can be used to create a mapping from it. Breakpoints are removed from the copied macro.
  • deleteAllMacros: Copies the current macro in decoded form that can be used to

Tip

For recursive macros (playing a macro inside a macro), you can still use the default command @a.

Advanced Usage

Performance Optimizations

Running long macros or macros with a high count, can be demanding on the system and result in lags. For this reason, nvim-recorder provides some performance optimizations that are temporarily enabled when a macro with a high count is run.

Note that these optimizations do have some potential drawbacks.

  • lazyredraw disables redrawing of the screen, which makes it harder to notice edge cases not considered in the macro. It may also appear as if the screen is frozen for a while.
  • Disabling the system clipboard is mostly safe, if you do not intend to copy content to it with the macro.
  • Ignoring auto-commands is not recommended, when you rely on certain plugin functionality during the macro, since it can potentially disrupt those plugins' effect.

Macro Breakpoints

nvim-recorder allows you to set breakpoints in your macros, which can be helpful for debugging macros. Breakpoints are automatically ignored when you trigger the macro with a count.

Setting Breakpoints

  1. During a recording, press the addBreakPoint key (default: ##) in normal mode.
  2. After a recording, use editMacro and add or remove the ## manually.

Playing Macros with Breakpoints

  • Using the playMacro key, the macro automatically stops at the next breakpoint. The next time you press playMacro, the next segment of the macro is played.
  • Starting a new recording, editing a macro, yanking a macro, or switching macro slot all reset the sequence, meaning that playMacro starts from the beginning again.

Tip

You can do other things in between playing segments of the macro, like moving a few characters to the left or right. That way you can also use breakpoints to manually correct irregularities.

Ignoring Breakpoints
When you play the macro with a count (for example 50Q), breakpoints are automatically ignored.

Tip

Add a count of 1 (1Q) to play a macro once and still ignore breakpoints.

Shared Keybindings with nvim-dap
If you are using nvim-dap, you can use dapSharedKeymaps = true to set up the following shared keybindings:

  1. addBreakPoint maps to dap.toggle_breakpoint() outside a recording. During a recording, it adds a macro breakpoint instead.
  2. playMacro maps to dap.continue() if there is at least one DAP-breakpoint. If there is no DAP-breakpoint, plays the current macro-slot instead.

Note that this feature is experimental, since the respective API from nvim-dap is non-public and can be changed without deprecation notice.

Lazy-loading the plugin

nvim-recorder can be lazy-loaded, but the setup is a bit more complex than with other plugins.

nvim-recorder is best lazy-loaded on the mappings for startStopRecording and playMacro. However, it is still required to set the mappings to the setup call.

However, since using the status line components also results in loading the plugin. The loading of the status line components can be delayed by setting them in the plugin's config. The only drawback of this method is that no component is shown when until you start or play a recording (which you can completely disregard when you set clear = true, though).

Nonetheless, the plugin is pretty lightweight (~350 lines of code), so not lazy-loading it should not have a big impact.

-- minimal config for lazy-loading with lazy.nvim
{
	"chrisgrieser/nvim-recorder",
	dependencies = "rcarriga/nvim-notify",
	keys = {
		-- these must match the keys in the mapping config below
		{ "q", desc = "ο€½ Start Recording" },
		{ "Q", desc = "ο€½ Play Recording" },
	},
	config = function()
		require("recorder").setup({
			mapping = {
				startStopRecording = "q",
				playMacro = "Q",
			},
		})

			local lualineZ = require("lualine").get_config().sections.lualine_z or {}
			local lualineY = require("lualine").get_config().sections.lualine_y or {}
			table.insert(lualineZ, { require("recorder").recordingStatus })
			table.insert(lualineY, { require("recorder").displaySlots })

			require("lualine").setup {
				tabline = {
					lualine_y = lualineY,
					lualine_z = lualineZ,
				},
			}
	end,
},

About me

In my day job, I am a sociologist studying the social mechanisms underlying the digital economy. For my PhD project, I investigate the governance of the app economy and how software ecosystems manage the tension between innovation and compatibility. If you are interested in this subject, feel free to get in touch.

Blog
I also occasionally blog about vim: Nano Tips for Vim

Profiles

Buy Me a Coffee at ko-fi.com

Footnotes

  1. As opposed to vim, Neovim already allows you to use Q to play the last recorded macro. Considering this, the simplified controls really only save you one keystroke for one-off macros. However, as opposed to Neovim's built-in controls, you can still keep using Q for playing the not-most-recently recorded macro. ↩

nvim-recorder's People

Contributors

c-sinclair avatar chrisgrieser avatar rish987 avatar tylersaunders avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

nvim-recorder's Issues

[Bug]: Error when calling setup with no table

Bug Description

If you copy pasta the installation instruction for packer.nvim, you get the following error

packer.nvim: Error running config for nvim-recorder: ...im/site/pack/packer/start/nvim-recorder/lua/recorder.lua:198: attempt to index local 'config' (a nil value)

Relevant Screenshot

No response

To Reproduce

No response

neovim version

NVIM v0.9.0-dev-661+ga37c686d2
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3

Make sure you have done the following

  • I have updated to the latest version of the plugin.

utils module is required but not provided

packer.nvim: Error running config for nvim-recorder: ...im/site/pack/packer/start/nvim-recorder/lua/recorder.lua:1: module 'utils' not found:                                                                     β€’β”‚
β”‚^Ino field package.preload['utils']                                                                                                                                                                                β”‚
β”‚^Ino file './utils.lua'                                                                                                                                                                                            β”‚
β”‚^Ino file '/home/runner/work/neovim/neovim/.deps/usr/share/luajit-2.1.0-beta3/utils.lua'                                                                                                                           β”‚
β”‚^Ino file '/usr/local/share/lua/5.1/utils.lua'                                                                                                                                                                     β”‚
β”‚^Ino file '/usr/local/share/lua/5.1/utils/init.lua'                                                                                                                                                                β”‚
β”‚^Ino file '/home/runner/work/neovim/neovim/.deps/usr/share/lua/5.1/utils.lua'                                                                                                                                      β”‚
β”‚^Ino file '/home/runner/work/neovim/neovim/.deps/usr/share/lua/5.1/utils/init.lua'                                                                                                                                 β”‚
β”‚^Ino file '/home//.cache/nvim/packer_hererocks/2.1.0-beta3/share/lua/5.1/utils.lua'                                                                                                                        β”‚
β”‚^Ino file '/home//.cache/nvim/packer_hererocks/2.1.0-beta3/share/lua/5.1/utils/init.lua'                                                                                                                   β”‚
β”‚^Ino file '/home//.cache/nvim/packer_hererocks/2.1.0-beta3/lib/luarocks/rocks-5.1/utils.lua'                                                                                                               β”‚
β”‚^Ino file '/home//.cache/nvim/packer_hererocks/2.1.0-beta3/lib/luarocks/rocks-5.1/utils/init.lua'                                                                                                          β”‚
β”‚^Ino file './utils.so'                                                                                                                                                                                             β”‚
β”‚^Ino file '/usr/local/lib/lua/5.1/utils.so'                                                                                                                                                                        β”‚
β”‚^Ino file '/home/runner/work/neovim/neovim/.deps/usr/lib/lua/5.1/utils.so'                                                                                                                                         β”‚
β”‚^Ino file '/usr/local/lib/lua/5.1/loadall.so'                                                                                                                                                                      β”‚
β”‚^Ino file '/home//.cache/nvim/packer_hererocks/2.1.0-beta3/lib/lua/5.1/utils.so'                                                                                                                           β”‚
β”‚"[packer]"  133 lines --0%--                                                                                                                                                                                       β”‚
β”‚packer.nvim: Error running config for nvim-recorder: [string "..."]:0: loop or previous error loading module 'recorder'

I'm guessing the utils module is part of your neovim config somewhere.

[Bug]: When using special keys macro are not recorded properly

Bug Description

When using keys that are not "printable" as start startStopRecording the macro will be trimmed and not complete.

I identified where the issue is Happening

image

since the macro is cut weather or not the key is present, it will then remove part of the actual macro.

In my case the translated key is "<lt<f4>"

Here is my config

return {
  "chrisgrieser/nvim-recorder",
  opts = {
    mapping = {
      startStopRecording = "<F4>",
      playMacro = "<F5>",
      switchSlot = "<leader>ms",
      editMacro = "<leader>me",
      yankMacro = "<leader>my", -- also decodes it for turning macros to mappings
      addBreakPoint = "##", -- ⚠️ this should be a string you don't use in insert mode during a macro
    },
    dapSharedKeymaps = false,
  },
}

Thanks a lot for your great little plugin :)

Relevant Screenshot

No response

To Reproduce

No response

neovim version

NVIM v0.10.0-dev

Make sure you have done the following

  • I have updated to the latest version of the plugin.

[Bug]: calling setup with empty object throws error

Bug Description

Calling setup with an empty config object like so:

require("recorder").setup({})

Results in:

Error  10:54:25 AM notify.error packer.nvim: Error running config for nvim-recorder:     
...im/site/pack/packer/start/nvim-recorder/lua/recorder.lua:210: attempt to index field     'mapping' (a nil value)

I think it's related to how recorder.lua references config.mapping.$property

When I use the config in the README for default values, I don't receive the error. (i.e. the config.mapping.$property key exists

I'm seeing this behavior when installing from 7f4d8a0

Relevant Screenshot

No response

To Reproduce

  1. Install via packer following instructions in readme
  2. Pass empty config object (or no object at all) to the setup method
  3. observe.

neovim version

version NVIM v0.8.0-dev-1162-g2a3cb0893
version Build type: RelWithDebInfo
version LuaJIT 2.1.0-beta3
version Compilation: /usr/bin/gcc-10 -U_FORTIFY_SOURCE -D_FORTIF
    _SOURCE=1 -DNVIM_TS_HAS_SET_MATCH_LIMIT -DNVIM_TS_HAS_SET_ALLOCATOR -O2 -g -Og -g -Wall
    -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconve
    sion -Wdouble-promotion -Wmissing-noreturn -Wmissing-format-attribute -Wmissing-prototy
    es -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fno-common -fdiagnostics-colo
    =always -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVI
    _UNIBI_HAS_VAR_FROM -DMIN_LOG_LEVEL=3 -I/home/runner/work/neovim/neovim/build/cmake.con
    ig -I/home/runner/work/neovim/neovim/src -I/home/runner/work/neovim/neovim/.deps/usr/in
    lude -I/usr/include -I/home/runner/work/neovim/neovim/build/src/nvim/auto -I/home/runne
    /work/neovim/neovim/build/include

Make sure you have done the following

  • I have updated to the latest version of the plugin.

[Bug]: Failed to run `config` for nvim-recorder

Bug Description

I got the error below when I try to run recorder.setup()

Failed to run `config` for nvim-recorder

...02/.local/share/nvim/lazy/nvim-recorder/lua/recorder.lua:293: bad argument #1 to 'pairs' (table expected, got nil)

Here is my config if it'll be helpful

local status_ok, recorder = pcall(require, "recorder")
if not status_ok then
  vim.notify("Recorder not found!")
  return
end

recorder.setup({
  slots = { "a", "b" },
  mapping = {
    startStopRecording = "q",
    playMacro = "Q",
    editMacro = "cq",
    switchSlot = "<C-A-q>",
  },
  clear = false,
  logLevel = vim.log.levels.INFO,
  dapSharedKeymaps = false,
})

Relevant Screenshot

No response

To Reproduce

  1. Call require('recorder').setup in nvim config
  2. Open neovim

neovim version

NVIM v0.10.0-dev-737+gdf2f5e391

Make sure you have done the following

  • I have updated to the latest version of the plugin.

[Bug]: Conflict with the latest lualine

Bug Description

the position of lualine changes from the bottom to the top

my config

local M = {}

-- 廢迟加载
M.recoderConfig = function()
	local recoder = try_require("recorder")
	if recoder == nil then
		return
	end

	local lualine = try_require("lualine")
	if lualine == nil then
		return
	end

	recoder.setup({
		mapping = {
			startStopRecording = "q",
			playMacro = "Q",
		},
	})

	local lualineZ = lualine.get_config().sections.lualine_z or {}
	local lualineY = lualine.get_config().sections.lualine_y or {}
	table.insert(lualineZ, { recoder.recordingStatus })
	table.insert(lualineY, { recoder.displaySlots })

	lualine.setup({
		tabline = {
			lualine_y = lualineY,
			lualine_z = lualineZ,
		},
	})
end

return M

Relevant Screenshot

2024-04-11.18.44.01.mov

To Reproduce

Reproduction steps

  1. Install the latest lualine and nvim-recoder
  2. press q, q
  3. switch another buffer

neovim version

$ lvim --version
NVIM v0.9.5
Build type: Release
LuaJIT 2.1.1703358377

Make sure you have done the following

  • I have updated to the latest version of the plugin.

Jump to Specific Register

Feature Requested

Hello,

Thanks for making this plugin!

I’ve currently got it set up to use a few different registers, like a, b, c, d, and e. I’d like to be able to switch directly from register a to any other register, without having to cycle through all of the others. This is because some of the registers may contain content that I want to keep.

Is this something you might consider adding natively via a configuration keybinding?

Relevant Screenshot

No response

Checklist

  • The feature would be useful to more users than just me.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.