From fcbdefe39ef741f8fdcd23cbc537b2e16ccd2490 Mon Sep 17 00:00:00 2001 From: Tom van der Lee Date: Thu, 24 Sep 2026 19:43:46 +0200 Subject: Fixed stuff --- neovim/.config/nvim/lua/config/autocmds.lua | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'neovim/.config/nvim/lua') 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", { callback = strip_trailing_whitespace, }) +-- Make the directory Neovim was opened with (`nvim .`, `nvim ~/project`, +-- `nvim /some/dir`) the cwd for the whole session, not just the cwd of the +-- directory-listing buffer it shows. Only fires for the "single directory +-- argument" invocation; opening files, multiple args, or no args leaves cwd +-- untouched. Uses chdir() (global scope, like :cd) rather than :lcd/:tcd +-- since this should apply session-wide. This itself fires DirChanged, so +-- the handler below re-runs and correctly picks up a .nvim.lua for the new +-- directory too. +vim.api.nvim_create_autocmd("VimEnter", { + callback = function() + if vim.fn.argc() ~= 1 then + return + end + local arg = vim.fn.argv(0) + if vim.fn.isdirectory(arg) == 0 then + return + end + vim.fn.chdir(vim.fn.fnamemodify(arg, ":p")) + end, +}) + -- Project-local config: search upward from cwd for a .nvim.lua, the same -- nearest-ancestor pattern LSP root-dir detection uses, so it's found -- regardless of exactly which subdirectory Neovim's cwd is or how you got -- cgit v1.3