From 6576e75eeb7d0a028638748b2009c5eb0eec720f Mon Sep 17 00:00:00 2001 From: Barrett Ruth <62671086+barrettruth@users.noreply.github.com> Date: Fri, 26 Jun 2026 05:17:00 -0500 Subject: [PATCH] feat(dir.lua): global "-" default mapping #40426 --- runtime/doc/plugins.txt | 5 +++++ runtime/doc/usr_22.txt | 3 ++- runtime/plugin/dir.lua | 4 ++++ test/functional/plugin/dir_spec.lua | 12 ++++++++++++ 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/runtime/doc/plugins.txt b/runtime/doc/plugins.txt index 7b802f0a38..04325b076f 100644 --- a/runtime/doc/plugins.txt +++ b/runtime/doc/plugins.txt @@ -49,6 +49,11 @@ Nvim opens a directory listing when |:edit| is used with a directory path. The listing is a buffer with 'filetype' set to "directory". Mappings: *dir-mappings* +> + - Open the parent directory of the current file or directory. +< + +Directory buffer mappings: *dir-buffer-mappings* > Open the file or directory under the cursor. - Open the parent directory. diff --git a/runtime/doc/usr_22.txt b/runtime/doc/usr_22.txt index 949a563caa..f6edcefd80 100644 --- a/runtime/doc/usr_22.txt +++ b/runtime/doc/usr_22.txt @@ -42,7 +42,8 @@ Directories end in "/". You can use Normal mode Vim commands to move around in the text. For example, move the cursor atop a file and press ; you will then be editing that -file. To go back to the listing use ":edit ." again. CTRL-O also works. +file. Press "-" to open the parent directory of the current file or +directory. CTRL-O also works. Try using while the cursor is atop a directory name. The result is that the file browser moves into that directory and displays the items found diff --git a/runtime/plugin/dir.lua b/runtime/plugin/dir.lua index eea0105c47..f89804dcee 100644 --- a/runtime/plugin/dir.lua +++ b/runtime/plugin/dir.lua @@ -18,6 +18,10 @@ vim.keymap.set('n', '(nvim-dir-reload)', function() require('nvim.dir')._reload() end, { silent = true, desc = 'Reload directory' }) +if vim.fn.mapcheck('-', 'n') == '' and vim.fn.hasmapto('(nvim-dir-up)', 'n') == 0 then + vim.keymap.set('n', '-', '(nvim-dir-up)', { silent = true, desc = 'Open parent directory' }) +end + ---@param buf integer ---@param path string ---@return boolean diff --git a/test/functional/plugin/dir_spec.lua b/test/functional/plugin/dir_spec.lua index de73effd43..5f15d7d692 100644 --- a/test/functional/plugin/dir_spec.lua +++ b/test/functional/plugin/dir_spec.lua @@ -144,6 +144,18 @@ describe('nvim.dir', function() assert_directory(root) end) + it('maps - to open the parent directory of the current file', function() + make_fixture() + n.clear({ args_rm = { '-u' } }) + + edit(file) + feed('-') + poke_eventloop() + + assert_directory(root) + line_of('alpha.txt') + end) + it('uses an absolute buffer name for a relative startup directory argument', function() if t.is_zig_build() then return pending('broken with build.zig relative runtime paths after chdir')