Skip to content

feature: load plugin when root pattern detected #1980

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

Open
1 task done
hoofcushion opened this issue Apr 18, 2025 · 3 comments
Open
1 task done

feature: load plugin when root pattern detected #1980

hoofcushion opened this issue Apr 18, 2025 · 3 comments
Labels
enhancement New feature or request

Comments

@hoofcushion
Copy link

hoofcushion commented Apr 18, 2025

Did you check the docs?

  • 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

@hoofcushion hoofcushion added the enhancement New feature or request label Apr 18, 2025
@dpetka2001
Copy link
Contributor

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.

@hoofcushion
Copy link
Author

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

@hoofcushion
Copy link
Author

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"},
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants