From d876425956ca3e008d618b18ea3b9939014f97b4 Mon Sep 17 00:00:00 2001 From: ray Date: Mon, 12 Jan 2026 15:18:10 +0000 Subject: [PATCH] Update README and keymaps for netrw navigation Add command variants for netrw and update keymaps to improve navigation experience. Store initial working directory as project root for better symlink handling. --- README.md | 16 ++++++++++++++-- lua/netrw-config.lua | 17 +++++++++++------ lua/settings.lua | 4 ++++ 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 58239a2..ad3d45e 100644 --- a/README.md +++ b/README.md @@ -52,12 +52,24 @@ Core keymaps available globally (not plugin-specific). These provide fallbacks f ### `lua/netrw-config.lua` +#### `:Ex` Command Variants + +| Command | Opens netrw at | +| --- | --- | +| `:Ex` | Current working directory (`:pwd`) | +| `:Ex .` | Current file's directory | +| `:Ex %:h` | Current file's directory (explicit) | +| `:Ex /path/to/dir` | Specific path | + #### Custom Keymaps | Mode | Key | Description | | --- | --- | --- | -| n | `te` | Open netrw in a new tab rooted at current file directory | -| n | `tE` | Open netrw in a new tab rooted at project cwd | +| n | `nt` | Open netrw in new tab at current file's directory | +| n | `nT` | Open netrw in new tab at project root | +| n | `nr` | Open netrw in current window at project root | + +**Note:** Project root is stored as the initial working directory when Neovim starts. This allows navigation back to the project root even after following symlinks to external directories. #### Default Netrw Keymaps diff --git a/lua/netrw-config.lua b/lua/netrw-config.lua index 8f8870d..b4f2087 100644 --- a/lua/netrw-config.lua +++ b/lua/netrw-config.lua @@ -40,17 +40,22 @@ vim.g.netrw_sizestyle = 'H' -- Netrw file explorer keymaps -- Open netrw in new tab at current file's directory -map('n', 'te', function() +map('n', 'nt', function() local current_file_dir = vim.fn.expand('%:p:h') vim.cmd('tabnew') vim.cmd('Explore ' .. vim.fn.fnameescape(current_file_dir)) -end, { desc = 'Netrw: Tab explore (current file dir)', silent = true }) +end, { desc = 'Netrw: Tab at current file dir', silent = true }) --- Open netrw in new tab at project root (cwd) -map('n', 'tE', function() +-- Open netrw in new tab at project root (stored at startup) +map('n', 'nT', function() vim.cmd('tabnew') - vim.cmd('Explore ' .. vim.fn.fnameescape(vim.fn.getcwd())) -end, { desc = 'Netrw: Tab explore (project root)', silent = true }) + vim.cmd('Explore ' .. vim.fn.fnameescape(vim.g.project_root)) +end, { desc = 'Netrw: Tab at project root', silent = true }) + +-- Open netrw in current window at project root (stored at startup) +map('n', 'nr', function() + vim.cmd('Explore ' .. vim.fn.fnameescape(vim.g.project_root)) +end, { desc = 'Netrw: Open at project root', silent = true }) -- Enable line numbers in netrw buffers vim.api.nvim_create_autocmd('FileType', { pattern = 'netrw', diff --git a/lua/settings.lua b/lua/settings.lua index d44a895..1a76db1 100644 --- a/lua/settings.lua +++ b/lua/settings.lua @@ -5,6 +5,10 @@ vim.g.loaded_ruby_provider = 0 vim.g.loaded_perl_provider = 0 vim.g.loaded_node_provider = 0 +-- Store initial working directory as project root +-- Used by netrw navigation to return to project root after following symlinks +vim.g.project_root = vim.fn.getcwd() + -- Enable project-local configuration files vim.opt.exrc = true -- Load .nvim.lua from project root vim.opt.secure = true -- Prompt before loading untrusted files