diff options
Diffstat (limited to 'neovim/.config/nvim/lua')
| -rw-r--r-- | neovim/.config/nvim/lua/config/autocmds.lua | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/neovim/.config/nvim/lua/config/autocmds.lua b/neovim/.config/nvim/lua/config/autocmds.lua index e9ebe04..5ebe5ec 100644 --- a/neovim/.config/nvim/lua/config/autocmds.lua +++ b/neovim/.config/nvim/lua/config/autocmds.lua | |||
| @@ -13,6 +13,27 @@ vim.api.nvim_create_autocmd("BufWritePre", { | |||
| 13 | callback = strip_trailing_whitespace, | 13 | callback = strip_trailing_whitespace, |
| 14 | }) | 14 | }) |
| 15 | 15 | ||
| 16 | -- Make the directory Neovim was opened with (`nvim .`, `nvim ~/project`, | ||
| 17 | -- `nvim /some/dir`) the cwd for the whole session, not just the cwd of the | ||
| 18 | -- directory-listing buffer it shows. Only fires for the "single directory | ||
| 19 | -- argument" invocation; opening files, multiple args, or no args leaves cwd | ||
| 20 | -- untouched. Uses chdir() (global scope, like :cd) rather than :lcd/:tcd | ||
| 21 | -- since this should apply session-wide. This itself fires DirChanged, so | ||
| 22 | -- the handler below re-runs and correctly picks up a .nvim.lua for the new | ||
| 23 | -- directory too. | ||
| 24 | vim.api.nvim_create_autocmd("VimEnter", { | ||
| 25 | callback = function() | ||
| 26 | if vim.fn.argc() ~= 1 then | ||
| 27 | return | ||
| 28 | end | ||
| 29 | local arg = vim.fn.argv(0) | ||
| 30 | if vim.fn.isdirectory(arg) == 0 then | ||
| 31 | return | ||
| 32 | end | ||
| 33 | vim.fn.chdir(vim.fn.fnamemodify(arg, ":p")) | ||
| 34 | end, | ||
| 35 | }) | ||
| 36 | |||
| 16 | -- Project-local config: search upward from cwd for a .nvim.lua, the same | 37 | -- Project-local config: search upward from cwd for a .nvim.lua, the same |
| 17 | -- nearest-ancestor pattern LSP root-dir detection uses, so it's found | 38 | -- nearest-ancestor pattern LSP root-dir detection uses, so it's found |
| 18 | -- regardless of exactly which subdirectory Neovim's cwd is or how you got | 39 | -- regardless of exactly which subdirectory Neovim's cwd is or how you got |
