From bec45db76de676e48436270b452a51b0a9ddcbcc Mon Sep 17 00:00:00 2001 From: Cian Hughes Date: Tue, 3 Feb 2026 12:48:29 +0000 Subject: [PATCH] Added project awareness to neovim --- lua/config/init.lua | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lua/config/init.lua b/lua/config/init.lua index 3c5c1d7..bf8b31a 100644 --- a/lua/config/init.lua +++ b/lua/config/init.lua @@ -20,6 +20,22 @@ if (vim.fn.executable("nu") == 1) and shell_path:find("nu") then vim.opt.shellpipe = "| complete | update stderr { ansi strip } | tee { get stderr | save --force --raw %s } | into record" end +-- Check if we're inside a git repo, and if we are make the project root the CWD +vim.api.nvim_create_autocmd("VimEnter", { + callback = function() + local current_file = vim.fn.expand("%:p") + if current_file == "" then + return + end + local root_dir = vim.fs.dirname( + vim.fs.find({ ".git" }, { upward = true, path = vim.fs.dirname(current_file) })[1] + ) + if root_dir then + vim.cmd.cd(root_dir) + print("Root changed to: " .. root_dir) + end + end, +}) -- Add custom commentstring definitions vim.api.nvim_create_autocmd("FileType", { pattern = "nix,flake",