From 4e9e22da00680053d9a6161dfe46bad78c85b5df Mon Sep 17 00:00:00 2001 From: ray Date: Mon, 12 Jan 2026 19:24:41 +0000 Subject: [PATCH] fix working directory issues --- LOG.md | 1 + MIGRATION_PLAN.md | 1 + README.md | 10 ++++++++++ lua/netrw-config.lua | 4 +++- lua/plugins/telescope.lua | 3 +++ lua/settings.lua | 3 +++ 6 files changed, 21 insertions(+), 1 deletion(-) diff --git a/LOG.md b/LOG.md index 93def00..4716ef8 100644 --- a/LOG.md +++ b/LOG.md @@ -26,6 +26,7 @@ Record every decision here with a short rationale. Append new entries; do not re - Add Oil.nvim for file manipulation (rename/move/delete with buffer sync) - netrw for tree view and preview splits; Oil for operations that would break buffer names - PHP `gf` enhancement via `includeexpr` for WordPress/PHP path resolution + - **Working directory locked to project root**: Disabled `autochdir`, set `netrw_keepdir = 1`, captured initial cwd in `vim.g.project_root`, configured Telescope to always search from project root regardless of current buffer - 2025-12-07: Treesitter Phase 5 decisions: - Focus on core languages: PHP, HTML, JavaScript, TypeScript, CSS, Markdown, Lua, Bash, JSON - Enable syntax highlighting with performance safeguard (disable for files >100KB) diff --git a/MIGRATION_PLAN.md b/MIGRATION_PLAN.md index e0c82b4..56fe7d0 100644 --- a/MIGRATION_PLAN.md +++ b/MIGRATION_PLAN.md @@ -474,6 +474,7 @@ Source of truth for the step-by-step rebuild. Keep this concise and up to date. - [ ] Validate Telescope navigation + LSP jumps - [ ] Validate netrw browsing and preview splits - [ ] Validate Oil.nvim file operations +- [x] Fix working directory behavior (disabled autochdir, locked Telescope to project root) ## Phase 12.5 — Language tooling validation - [ ] Validate HTML/PHP/JS/Markdown tooling diff --git a/README.md b/README.md index 14e780b..9378af2 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,16 @@ Living reference for session management, keymaps, commands, and plugin-specific features in this config. +## Working Directory Behavior + +The working directory (`:pwd`) is locked to the directory where you opened Neovim and does NOT change when switching files: + +- `autochdir` is disabled (working directory stays fixed at project root) +- `netrw_keepdir = 1` prevents netrw from changing directory when browsing +- Project root is captured at startup in `vim.g.project_root` (used by Telescope and netrw) +- Telescope searches from the initial project root regardless of current buffer +- Use `:cd ` to manually change directory if needed (affects Telescope search scope) + ## Session Management Session support is automatic but user-controlled: diff --git a/lua/netrw-config.lua b/lua/netrw-config.lua index 7855ba6..de3e558 100644 --- a/lua/netrw-config.lua +++ b/lua/netrw-config.lua @@ -20,7 +20,9 @@ vim.g.netrw_alto = 0 -- 50% split when pressing 'p' vim.g.netrw_winsize = 50 -vim.g.netrw_keepdir = 0 +-- Keep working directory unchanged when browsing (1 = don't change directory) +-- Setting to 1 prevents netrw from changing vim's working directory +vim.g.netrw_keepdir = 1 -- Open files in the same window (replace netrw buffer) -- Options: 0=same window, 1=horizontal split, 2=vertical split, 3=new tab, 4=previous window diff --git a/lua/plugins/telescope.lua b/lua/plugins/telescope.lua index 997a60c..5ff9b49 100644 --- a/lua/plugins/telescope.lua +++ b/lua/plugins/telescope.lua @@ -19,6 +19,9 @@ return { telescope.setup({ defaults = { + -- Always search from project root (where Neovim was opened) + cwd = vim.g.project_root, + -- Minimal UI, keep it clean prompt_prefix = '> ', selection_caret = '> ', diff --git a/lua/settings.lua b/lua/settings.lua index 1a76db1..19f96fe 100644 --- a/lua/settings.lua +++ b/lua/settings.lua @@ -9,6 +9,9 @@ vim.g.loaded_node_provider = 0 -- Used by netrw navigation to return to project root after following symlinks vim.g.project_root = vim.fn.getcwd() +-- Prevent automatic directory changes when switching files +vim.opt.autochdir = false -- Keep working directory at project root + -- Enable project-local configuration files vim.opt.exrc = true -- Load .nvim.lua from project root vim.opt.secure = true -- Prompt before loading untrusted files