From e3c5974adf25002ea490719a3391d790bd3a3353 Mon Sep 17 00:00:00 2001 From: Barrett Ruth <62671086+barrettruth@users.noreply.github.com> Date: Mon, 27 Jul 2026 17:30:54 -0500 Subject: [PATCH] feat(dir): open cwd with `1-` #40948 --- runtime/doc/plugins.txt | 16 ++++++++-------- runtime/plugin/dir.lua | 4 ++++ test/functional/plugin/dir_spec.lua | 6 +++--- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/runtime/doc/plugins.txt b/runtime/doc/plugins.txt index e6997ced41..b80f0f454b 100644 --- a/runtime/doc/plugins.txt +++ b/runtime/doc/plugins.txt @@ -54,16 +54,16 @@ To disable the built-in directory browser, set this before startup: >lua < Mappings: *dir-mappings* -> - - Open the parent directory of the current file or directory. -< + +• - opens the parent directory of the current file or directory. +• {count}- is like -, but a count of 1 opens the current working directory, + and a higher count goes up that many levels. Directory buffer mappings: *dir-buffer-mappings* -> - Open the file or directory under the cursor. - - Open the parent directory. - R Reload the directory listing. -< + +• opens the file or directory under the cursor. +• - opens the parent directory. +• R reloads the directory listing. These keys map to (nvim-dir-open), (nvim-dir-up), and (nvim-dir-reload); map those to use different keys. Default mappings are diff --git a/runtime/plugin/dir.lua b/runtime/plugin/dir.lua index cf01290c31..e39fde8ab8 100644 --- a/runtime/plugin/dir.lua +++ b/runtime/plugin/dir.lua @@ -11,6 +11,10 @@ vim.keymap.set('n', '(nvim-dir-open)', function() end, { silent = true, desc = 'Open directory entry' }) vim.keymap.set('n', '(nvim-dir-up)', function() + if vim.v.count == 1 then + api.nvim_cmd({ cmd = 'edit', args = { '.' }, magic = { file = false, bar = false } }, {}) + return + end local dir = require('nvim.dir') for _ = 1, vim.v.count1 do dir._open_parent() diff --git a/test/functional/plugin/dir_spec.lua b/test/functional/plugin/dir_spec.lua index ac56df18eb..54f9a6e95c 100644 --- a/test/functional/plugin/dir_spec.lua +++ b/test/functional/plugin/dir_spec.lua @@ -347,9 +347,10 @@ describe('nvim.dir', function() eq('new:2', exec_lua('return vim.g.nvim_dir_provider_list')) end) - it('maps [count]- to open parent directories', function() + it('maps [count]- to open directories', function() make_fixture() n.clear({ args_rm = { '--cmd' }, args = { '--clean' } }) + local cwd = vim.fs.normalize(fn.getcwd()) edit(file) feed('-') @@ -365,8 +366,7 @@ describe('nvim.dir', function() feed('1-') poke_eventloop() - assert_directory(root) - eq('alpha.txt', api.nvim_get_current_line()) + assert_directory(cwd) edit(file) feed('2-')