• Stars
    star
    202
  • Rank 193,691 (Top 4 %)
  • Language
    Lua
  • License
    MIT License
  • Created almost 2 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Enhance the usage of macros in Neovim.

nvim-recorder 📹

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 used after
	-- startup.
	slots = { "a", "b" },

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

	-- 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()

-- 💡 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 },
},
-- 💡 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 macro.

💡 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 if 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 certain autocmds is not recommended, when you rely on certain plugin functionality during the macro, since it can potentially disrupt those plugin's 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.

💡 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.

💡 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

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

nvim-recorder is best lazy-loaded on the keymappings for startStopRecording and playMacro. However, it is still required to set the keymappings 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

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.

More Repositories

1

shimmering-obsidian

Alfred Workflow with dozens of features for controlling your Obsidian vault.
JavaScript
811
star
2

nvim-spider

Use the w, e, b motions like a spider. Move by subwords and skip insignificant punctuation.
Lua
580
star
3

nvim-various-textobjs

Bundle of more than 30 new text objects for Neovim.
Lua
510
star
4

shimmering-focus

Minimalistic Obsidian Theme for keyboard-centric users.
CSS
469
star
5

nvim-scissors

Automagical editing and creation of snippets.
Lua
327
star
6

nvim-genghis

Lightweight and quick file operations without being a full-blown file manager.
Lua
195
star
7

nvim-early-retirement

Send buffers into early retirement by automatically closing them after x minutes of inactivity.
Lua
170
star
8

nvim-origami

Fold with relentless elegance.
Lua
160
star
9

nvim-tinygit

A lightweight bundle of commands focussed on swift and streamlined git operations.
Lua
143
star
10

alfred-bibtex-citation-picker

Citation picker & lightweight reference manager for BibTeX files, via Alfred.
JavaScript
138
star
11

nvim-rip-substitute

Perform search and replace operations in the current buffer using a modern user interface and contemporary regex syntax.
Lua
133
star
12

obsidian-smarter-md-hotkeys

A plugin for Obsidian providing hotkeys that select words and lines in a smart way before applying markup. Multiple cursors are supported as well.
TypeScript
132
star
13

nvim-kickstart-python

A launch point for your nvim configuration for Python
Lua
113
star
14

pandoc_alfred

Pandoc-Suite for Academic Writing in Markdown
JavaScript
98
star
15

obsidian-theme-design-utilities

Some Utilities and Quality-of-Life Features for Designers of Obsidian Themes
TypeScript
95
star
16

nvim-chainsaw

Speed up log creation. Create various kinds of language-specific log statements, such as logs of variables, assertions, or time-measuring.
Lua
92
star
17

finder-vim-mode

Feature-rich mouseless control of macOS Finder, inspired by vim/ranger.
Shell
81
star
18

.config

My personal dotfiles
Python
74
star
19

pdf-annotation-extractor-alfred

Alfred Workflow to extract annotations from PDF files.
JavaScript
72
star
20

nvim-rulebook

Add inline-comments to ignore rules, or lookup rule documentation online.
Lua
69
star
21

nvim-lsp-endhints

Display LSP inlay hints at the end of the line, rather than within the line.
Lua
66
star
22

nvim-puppeteer

Automatically convert strings to f-strings or template strings and back.
Lua
56
star
23

obsidian-divide-and-conquer

An Obsidian plugin that provides commands for bulk enabling/disabling of plugins. Useful for debugging when you have many plugins.
TypeScript
55
star
24

obsidian-quadro

Obsidian Plugin for social-scientific Qualitative Data Analysis (QDA). An open alternative to MAXQDA and atlas.ti, using Markdown to store data and research codes.
TypeScript
49
star
25

zsh-magic-dashboard

Pressing "enter" on an empty buffer displays an information-rich and pretty dashboard.
Shell
48
star
26

grappling-hook

Obsidian Plugin for blazingly fast file switching. For those who find the Quick Switcher still too slow.
TypeScript
44
star
27

nvim-alt-substitute

A substitute of vim's :substitute that uses lua patterns instead of vim regex. Supports incremental preview.
Lua
43
star
28

new-tab-default-page

Obsidian plugin to open a note of your choice when creating a new tab, like in the browser.
TypeScript
42
star
29

cmp-nerdfont

nvim-cmp source for nerdfont icons
Lua
40
star
30

alfred-neovim-utilities

Search neovim plugins and online :help via Alfred
JavaScript
34
star
31

cmp_yanky

cmp-source for clipboard history from yanky.nvim
Lua
34
star
32

nvim-dr-lsp

Status line component showing the number of LSP definition and reference of the token under the cursor.
Lua
27
star
33

alfred-docs-searches

Search more than two dozen official documentation sites via Alfred
JavaScript
25
star
34

twitter-workspace-for-drafts

Various capabilities for composing tweets in the Drafts app.
22
star
35

obsidian-sembr

Obsidian Plugin for Semantic Line Breaks
TypeScript
22
star
36

nvim-pseudometa-plugin-template

A template for new nvim plugins
Shell
22
star
37

alfred-reddit-browser

Browse your favorite subreddits (and hackernews) via Alfred.
JavaScript
20
star
38

obsidian-footnote-indicator

Indicates the presence of footnotes in the gutter and the Status bar
Shell
20
star
39

alfred-atop

System Monitoring and Process Management via Alfred
JavaScript
19
star
40

gitfred

Helpful GitHub Assistant for Alfred.
JavaScript
17
star
41

alfred-homebrew

Search, install, or uninstall homebrew packages conveniently via Alfred.
JavaScript
16
star
42

pdf-summarizer-alfred

Get summaries of your PDFs via ChatPDF.
Shell
14
star
43

hyper-seek

Alfred workflow that shows inline search results, without a keyword.
JavaScript
13
star
44

obsidian-extra-md-commands

Obsidian plugin that adds various commands, e.g. for __bold__ or <cite>.
TypeScript
12
star
45

alfred-writing-assistant

Autocorrection, synonym suggestions for the word under the cursor, and rephrasing of the selected text. All with one key press.
JavaScript
12
star
46

obsidian-sidebar-toggler

Finer control of the Obsidian sidebars. To be used with an external window manager.
TypeScript
11
star
47

wrench-knife

Collection of useful snippets for Hammerspoon
Lua
11
star
48

obsidian-nothing

An Obsidian plugin that adds a no-op command.
Shell
11
star
49

alfred-workflow-template

Shell
10
star
50

pseudometa-obsidian-plugin-template

A description for the plugin
JavaScript
9
star
51

pdf-annotation-extractor

Extracts Annotations from PDFs as well-formatted markdown
JavaScript
9
star
52

alfred-themes

A small collection of Alfred Themes I designed
8
star
53

alfred-pass

Alfred Client for the pass-cli
Shell
8
star
54

dotfiles-old

pseudometa's dotfiles
TeX
7
star
55

obsidian-smarter-paste

Improvements for when you paste things into Obsidian
TypeScript
7
star
56

alfred-wikipedia-suggest

Get in-line Wikipedia search suggestions
JavaScript
7
star
57

alfred-read-later

Simple standalone read-later-app for Alfred. Saves the items in plaintext on your device.
JavaScript
7
star
58

alfred-steam-companion

Alfred Workflow that interacts with Steam. Launches games directly, creates aliases, uninstalls games, and searches the Steam Store
6
star
59

drafts-snooze

Combination of settings, draft actions and shortcuts to enable the snoozing of drafts.
5
star
60

obsidian-task-statusbar

Obsidian plugin that displays the number of completed and total tasks in the status bar.
Shell
4
star
61

portfolio-performance-alfred

Searches your watchlists in the Portfolio Performance App for securities. Select one to copy its Name, Symbol, ISIN, or WKN to the clipboard.
JavaScript
4
star
62

alfred-anime-search

Search animes listed in the myanimelist database. Open entries at myanimelist or AniList.
JavaScript
3
star
63

tot-alfred

Tot.app Integration for Alfred.
JavaScript
3
star
64

chrisgrieser

2
star
65

axelrod-prisoner-dilemma

Recreation of the prisoner's dilemma model from Axelrod's "Evolution of Cooperation" in Python
Python
2
star
66

obsidian-personal-plugin

Personal Obsidian plugin, containing features customized to my workflow.
TypeScript
2
star
67

apuz-gender-analyzer

Analysis of the genders of the authors at the German journal "Aus Politik und Zeitgeschichte" (APuZ)
Python
2
star
68

quadro-example-vault

Example vault for Quadro, the QDA Plugin for Obsidian.
Makefile
2
star
69

alfred-reminders-companion

Display and edit reminders due today.
JavaScript
2
star
70

name-gender-analyzer

Makefile
1
star
71

test-repo

This repo is currently only used for testing GitHub Release Actions
Shell
1
star
72

nanotipsforvim-blog

source for the blog
Just
1
star
73

alfred-japanese-dictionary

Japanese-English Dictionary using jisho.org with audio, csv export of words, and preview of dictionary sites.
JavaScript
1
star
74

alfred-workflow-devtools

Various utilities and quality-of-life-features for Alfred workflow developers
Shell
1
star
75

alfred-dock-switcher

Switch between dock layouts.
Shell
1
star
76

alfred-quick-file-access

Quickly access recent files, files with a specific tag, files in the current window, files in the downloads folder, or trashed files.
JavaScript
1
star