feature: load plugin when root pattern detected
Did you check the docs?
- [x] I have read all the lazy.nvim docs
Is your feature request related to a problem? Please describe.
Currently, lazy.nvim uses events, filetypes, commands, and keymaps to load plugins. However, project-specific plugins don't fit well with these existing handlers. For example:
- Plugins like lewis6991/gitsigns.nvim should load when a .git directory is present
- zk-org/zk-nvim should load when a .zk directory exists
Describe the solution you'd like
A new handler to detect root pattern when DirChanged or BufRead, and use vim.fs.root(0,patterns).
pesudo code:
lazy.setup({
{"lewis6991/gitsigns.nvim", rootpattern={".git"}},
})
Describe alternatives you've considered
pass
Additional context
No response
You can do that with cond property already. Something like
cond = function()
return vim.uv.fs_stat(vim.loop.cwd() .. "/.git") or vim.fn.finddir(".git", ";") ~= ""
end,
Just specify the cond in each plugin spec that you want.
root pattern has to be check on each dir change or buf read, not startup stage, and a false cond is gonna disable the plugin, was not what it meant
This can be a workaround:
vim.api.nvim_create_autocmd("BufRead",{
callback = function()
if vim.fs.root(0,".git")~=nil then
vim.api.nvim_exec_autocmds("User",{data="RootPattern: .git"})
end
end
})
lazy.setup({
{"lewis6991/gitsigns.nvim", event="User RootPattern: .git"},
})
not interested in adding this