diff options
| author | Yochem van Rosmalen <git@yochem.nl> | 2025-05-11 18:00:51 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-05-11 11:00:51 -0500 |
| commit | 23bf4c0531acef4e8252f4db13fcd90ad5aa91bf (patch) | |
| tree | 2f9319b75ee959eb872fc8f06964a3b1f2b5c502 /runtime/lua/vim | |
| parent | 2c07428966a74c76003e00e2a37bf98eb8802c93 (diff) | |
feat(exrc): search in parent directories (#33889)
feat(exrc): search exrc in parent directories
Problem:
`.nvim.lua` is only loaded from current directory, which is not flexible
when working from a subfolder of the project.
Solution:
Also search parent directories for configuration file.
Diffstat (limited to 'runtime/lua/vim')
| -rw-r--r-- | runtime/lua/vim/_defaults.lua | 23 | ||||
| -rw-r--r-- | runtime/lua/vim/_meta/options.lua | 6 |
2 files changed, 26 insertions, 3 deletions
diff --git a/runtime/lua/vim/_defaults.lua b/runtime/lua/vim/_defaults.lua index adec7bda93..d0b3fea389 100644 --- a/runtime/lua/vim/_defaults.lua +++ b/runtime/lua/vim/_defaults.lua @@ -925,6 +925,29 @@ do end end end + + vim.api.nvim_create_autocmd('VimEnter', { + group = vim.api.nvim_create_augroup('nvim.find_exrc', {}), + desc = 'Find project-local configuration', + callback = function() + if vim.o.exrc then + local files = vim.fs.find( + { '.nvim.lua', '.nvimrc', '.exrc' }, + { type = 'file', upward = true, limit = math.huge } + ) + for _, file in ipairs(files) do + local trusted = vim.secure.read(file) --[[@as string|nil]] + if trusted then + if vim.endswith(file, '.lua') then + loadstring(trusted)() + else + vim.api.nvim_exec2(trusted, {}) + end + end + end + end + end, + }) end --- Default options diff --git a/runtime/lua/vim/_meta/options.lua b/runtime/lua/vim/_meta/options.lua index c6b9d7a875..79035d420d 100644 --- a/runtime/lua/vim/_meta/options.lua +++ b/runtime/lua/vim/_meta/options.lua @@ -2076,9 +2076,9 @@ vim.bo.expandtab = vim.o.expandtab vim.bo.et = vim.bo.expandtab --- Enables project-local configuration. Nvim will execute any .nvim.lua, ---- .nvimrc, or .exrc file found in the `current-directory`, if the file is ---- in the `trust` list. Use `:trust` to manage trusted files. See also ---- `vim.secure.read()`. +--- .nvimrc, or .exrc file found in the `current-directory` and all parent +--- directories (ordered upwards), if the files are in the `trust` list. +--- Use `:trust` to manage trusted files. See also `vim.secure.read()`. --- --- Compare 'exrc' to `editorconfig`: --- - 'exrc' can execute any code; editorconfig only specifies settings. |
