What
An autocmd that sources a .nvim.lua file from the project root whenever Neovim changes directory, enabling project-specific overrides without touching the global config.
Why it fits this setup
The config already uses lcd for per-window project roots and has vim.keymap.set("n", "<leader>e", ":edit **/*") for project-relative navigation. A .nvim.lua loader makes the project-root concept actionable: each repo can carry its own LSP tweaks, formatter choices, makeprg values, or iskeyword adjustments.
Sketch
-- add to options.lua or a new lua/config/project.lua
local function load_project_config()
local root = vim.fn.getcwd()
local nvim_lua = root .. "/.nvim.lua"
if vim.fn.filereadable(nvim_lua) == 1 then
-- sandbox: only source if the file is owned by the current user
local stat = vim.uv.fs_stat(nvim_lua)
if stat then
pcall(dofile, nvim_lua)
end
end
end
vim.api.nvim_create_autocmd({ "DirChanged", "VimEnter" }, {
callback = load_project_config,
})
Example .nvim.lua in a project
-- project root .nvim.lua
vim.opt_local.makeprg = "cargo build 2>&1"
vim.lsp.enable("rust_analyzer")
-- disable pyright for this non-Python repo
vim.lsp.enable("pyright", false)
Security note
Only source files owned by the current user (check via vim.uv.fs_stat uid or vim.fn.getfperm), and consider a vim.fn.confirm() prompt on first load (like vim's exrc with secure). Neovim's own exrc / 'secure' options do this for .nvim.lua natively since 0.9 — worth checking if simply enabling vim.o.exrc = true is sufficient before implementing a custom loader.
What
An autocmd that sources a
.nvim.luafile from the project root whenever Neovim changes directory, enabling project-specific overrides without touching the global config.Why it fits this setup
The config already uses
lcdfor per-window project roots and hasvim.keymap.set("n", "<leader>e", ":edit **/*")for project-relative navigation. A.nvim.lualoader makes the project-root concept actionable: each repo can carry its own LSP tweaks, formatter choices,makeprgvalues, oriskeywordadjustments.Sketch
Example
.nvim.luain a projectSecurity note
Only source files owned by the current user (check via
vim.uv.fs_statuid orvim.fn.getfperm), and consider avim.fn.confirm()prompt on first load (like vim'sexrcwithsecure). Neovim's ownexrc/'secure'options do this for.nvim.luanatively since 0.9 — worth checking if simply enablingvim.o.exrc = trueis sufficient before implementing a custom loader.