feat(dir.lua): global "-" default mapping #40426

This commit is contained in:
Barrett Ruth
2026-06-26 05:17:00 -05:00
committed by GitHub
parent ea0af59854
commit 6576e75eeb
4 changed files with 23 additions and 1 deletions

View File

@@ -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*
>
<CR> Open the file or directory under the cursor.
- Open the parent directory.

View File

@@ -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 <Enter>; 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 <Enter> while the cursor is atop a directory name. The result is
that the file browser moves into that directory and displays the items found

View File

@@ -18,6 +18,10 @@ vim.keymap.set('n', '<Plug>(nvim-dir-reload)', function()
require('nvim.dir')._reload()
end, { silent = true, desc = 'Reload directory' })
if vim.fn.mapcheck('-', 'n') == '' and vim.fn.hasmapto('<Plug>(nvim-dir-up)', 'n') == 0 then
vim.keymap.set('n', '-', '<Plug>(nvim-dir-up)', { silent = true, desc = 'Open parent directory' })
end
---@param buf integer
---@param path string
---@return boolean

View File

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