Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Global and a filetype-specific LazyKey mapping for the same key disable each other #1241

Closed
3 tasks done
chrisgrieser opened this issue Dec 28, 2023 · 2 comments · Fixed by #1284
Closed
3 tasks done
Labels
bug Something isn't working

Comments

@chrisgrieser
Copy link

Did you check docs and existing issues?

  • I have read all the lazy.nvim docs
  • I have searched the existing issues of lazy.nvim
  • I have searched the existing issues of plugins related to this issue

Neovim version (nvim -v)

NVIM v0.9.4

Operating system/version

macOS 14.1 (arm)

Describe the bug

This bug is related to the filetype-specific LazyKeys (#1076).

When setting two lazy keys, one global (without ft = …) and one for a buffer (with ft = …), activating one of them disables the other. While this makes somewhat sense for global keymaps to avoid conflicting keymaps, it is indeed often useful to modify the behavior of one keymap for a specific filetype. The current lazy.nvim behavior, however, prevents setting up such keymaps.

Steps To Reproduce

  1. Add this to any plugin spec:
keys = {
	{ "R", function() print("global") end},
	{ "R", function() print("local") end, ft = "lua"},
},
  1. Enter a lua file. Press R.
  2. Enter a non-lua file. Press R.

Expected Behavior

the keymaps should not disable each other

Repro

-- DO NOT change the paths and don't remove the colorscheme
local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
  vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", lazypath, })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
	{
		"folke/tokyonight.nvim",
		keys = {
			{ "R", function() print("global") end },
			{ "R", function() print("local") end, ft = "lua" },
		},
	},

}
require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

vim.cmd.colorscheme("tokyonight")
-- add anything else here
@chrisgrieser chrisgrieser added the bug Something isn't working label Dec 28, 2023
@folke folke closed this as completed in 5757b55 Jan 20, 2024
@chrisgrieser
Copy link
Author

Thanks for the fix!

Unfortunately, it does not seem to be working. As far as I can tell, it appears that now the global LazyKey is now completely ignored (using :Telescope keymap, the global mapping does not appear at all, only the buffer-local mapping does when in a buffer of the respective filetype.).

Also, when there is a filetype-specific LazyKey and a global keymap done independently from lazy, the global keymap is removed as soon as the LazyKey is triggered.

folke added a commit that referenced this issue Jan 21, 2024
@folke
Copy link
Owner

folke commented Jan 21, 2024

You were right. If the local mapping was used first, the global one got deleted.
Should be fixed now. (will make a new release later)

If not, please provide a repro like your original one and the steps to reproduce it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants