fix working directory issues

This commit is contained in:
Ray Elliott 2026-01-12 19:24:41 +00:00
parent 6aeb4ae913
commit 4e9e22da00
6 changed files with 21 additions and 1 deletions

1
LOG.md
View File

@ -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)

View File

@ -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

View File

@ -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 <path>` to manually change directory if needed (affects Telescope search scope)
## Session Management
Session support is automatic but user-controlled:

View File

@ -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

View File

@ -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 = '> ',

View File

@ -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