feat(dir): open cwd with 1- #40948

This commit is contained in:
Barrett Ruth 2026-07-27 17:30:54 -05:00 committed by GitHub
parent fbcb7a056c
commit e3c5974adf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 15 additions and 11 deletions

View File

@ -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*
>
<CR> Open the file or directory under the cursor.
- Open the parent directory.
R Reload the directory listing.
<
• <CR> opens the file or directory under the cursor.
• - opens the parent directory.
• R reloads the directory listing.
These keys map to <Plug>(nvim-dir-open), <Plug>(nvim-dir-up), and
<Plug>(nvim-dir-reload); map those to use different keys. Default mappings are

View File

@ -11,6 +11,10 @@ vim.keymap.set('n', '<Plug>(nvim-dir-open)', function()
end, { silent = true, desc = 'Open directory entry' })
vim.keymap.set('n', '<Plug>(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()

View File

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