nvim-mini / nvim-mini/mini.nvim
[mini.cmdline] keymaps that trigger command mode and involve the expression register desync the internal state, breaking autocompletion and peek
Nobody has claimed this yet.
- Dominant language
- Lua
- Stars
- 9.5k
- Forks
- 310
- Avg merge
- 4h 16m
- Merged PRs (30d)
- 1
Description
Contributing guidelines
- I have read CONTRIBUTING.md
- I have read CODE_OF_CONDUCT.md
- I have updated 'mini.nvim' to latest version of the
mainbranch
Module(s)
mini.cmdline
Neovim version
0.12.x
Description
Normal mode keymaps that both
- Start command mode without issuing a command
- Make use of the expression register
break the internal state of the plugin (H.cache.n_nested) which in turns break autocompletion and peek.
For example,
vim.keymap.set("n", "<F4>", ":<c-u> <c-r>=1<cr><home>")
triggers the bug while
vim.keymap.set("c", "<F4>", " <c-r>=1<cr><home>")
doesn't.
Logging the following information
_G.aux = {}
-- This is at the top of `H.on_cmdline_enter`
table.insert(aux, { 'enter', state = H.cache.state, n_nested = H.cache.n_nested })
-- This is at the top of `H.on_cmdline_leave`
table.insert(aux, { 'leave', state = H.cache.state, n_nested = H.cache.n_nested })
Using the previously mentioned keymap and closing the commandline results in the following
{
{ "leave" },
{ "enter" },
{ "leave" },
{ "enter" },
{
"enter",
state = <1>{
complpat = " 1",
compltype = "command",
line = " 1",
pos = 1,
},
},
{ "leave", n_nested = 1, state = <table 1> },
{ "enter", state = <table 1> },
{ "leave", n_nested = 1, state = <table 1> },
}
Since the first leave event happens before the first enter event, n_nested never goes back to 0 and both autocompletion and peek stop working.
This may happen because on
the CmdlineEnter callback is scheduled while the CmdlineLeave is not. There is more to it, though as the comment above the code points as this being intentional and the bug not happening outside of this niche case.
Reproduction
-
Create separate 'nvim-repro' config directory:
- '~/.config/nvim-repro/' on Unix
- '~/AppData/Local/nvim-repro/' on Windows
-
Inside 'nvim-repro' directory create a file named 'init.lua'.
Populate it with the following content:
-- Clone latest 'mini.nvim' (requires Git CLI installed)
vim.cmd('echo "Installing `mini.nvim`" | redraw')
local mini_path = vim.fn.stdpath("data") .. "/site/pack/deps/start/mini.nvim"
local clone_cmd = { "git", "clone", "--depth=1", "https://github.com/nvim-mini/mini.nvim", mini_path }
vim.fn.system(clone_cmd)
vim.cmd('echo "`mini.nvim` is installed" | redraw')
-- Make sure 'mini.nvim' is available
vim.cmd("packadd mini.nvim")
require("mini.deps").setup()
-- Add extra setup steps needed to reproduce the behavior
-- Use `MiniDeps.add('user/repo')` to install another plugin from GitHub
require("mini.cmdline").setup()
vim.keymap.set("n", "<F4>", ":<c-u> <c-r>=1<cr><home>")
-
Run
NVIM_APPNAME=nvim-repro nvim(i.e. executenvimwithNVIM_APPNAMEenvironment variable set to "nvim-repro").
Wait for all dependencies to install. -
:ato check that autocompletion works as expected -
<F4>to trigger the problematic keymap and<esc>to exit command mode -
The peek window won't be closed, close it manually with
:fclose -
:ato check that autocompletion is no longer working
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in lua/mini/cmdline.lua around the CmdlineEnter and CmdlineLeave handling at lines 580-583, then trace H.on_cmdline_enter, H.on_cmdline_leave, and H.cache.n_nested. Reproduce the issue with the F4 normal-mode keymap in the provided nvim-repro init.lua. Done means autocompletion and peek still work after exiting command mode triggered through the expression register.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- lua
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 64/100