project.nvim is an neovim plugin written in lua that provides project discovery management.
- Neovim >= 0.5.0
- Automagically cd to project directory using nvim lsp
- Dependency free, does not rely on lspconfig
- If no lsp then uses pattern matching to cd to root directory
Install the plugin with your preferred package manager:
{
'pze/project.nvim',
event = 'VeryLazy',
opts = {}
}
project.nvim comes with the following defaults:
{
-- Manual mode doesn't automatically change your root directory, so you have
-- the option to manually do so using `:ProjectRoot` command.
manual_mode = false,
-- Methods of detecting the root directory. **"lsp"** uses the native neovim
-- lsp, while **"pattern"** uses vim-rooter like glob pattern matching. Here
-- order matters: if one is not detected, the other is used as fallback. You
-- can also delete or rearangne the detection methods.
detection_methods = { "lsp", "pattern" },
-- All the patterns used to detect root dir, when **"pattern"** is in
-- detection_methods
patterns = { ".git", "_darcs", ".hg", ".bzr", ".svn", "Makefile", "package.json" },
-- Table of lsp clients to ignore by name
-- eg: { "efm", ... }
ignore_lsp = {},
-- Don't calculate root dir on specific directories
-- Ex: { "~/.cargo/*", ... }
exclude_dirs = {},
-- When set to false, you will get a message when project.nvim changes your
-- directory.
silent_chdir = true,
-- What scope to change the directory, valid options are
-- * global (default)
-- * tab
-- * win
scope_chdir = 'global',
}
Even if you are pleased with the defaults, please note that setup {}
must be
called for the plugin to start.
project.nvim's pattern engine uses the same expressions as vim-rooter, but for your convenience, I will copy paste them here:
To specify the root is a certain directory, prefix it with =
.
patterns = { "=src" }
To specify the root has a certain directory or file (which may be a glob), just give the name:
patterns = { ".git", "Makefile", "*.sln", "build/env.sh" }
To specify the root has a certain directory as an ancestor (useful for
excluding directories), prefix it with ^
:
patterns = { "^fixtures" }
To specify the root has a certain directory as its direct ancestor / parent
(useful when you put working projects in a common directory), prefix it with
>
:
patterns = { ">Latex" }
To exclude a pattern, prefix it with !
.
patterns = { "!.git/worktrees", "!=extras", "!^fixtures", "!build/env.sh" }
List your exclusions before the patterns you do want.
You can use User ProjectNvimSetPwd
autocmd to listen cwd changes.
vim.api.nvim_create_autocmd('User', {
pattern = 'ProjectNvimSetPwd',
callback = function(ctx)
local data = ctx.data
local dir = data.dir
local method = data.method
local scope = data.scope_chdir
end
})
- All pull requests are welcome.
- If you encounter bugs please open an issue.