mirror of
https://github.com/neovim/neovim.git
synced 2026-11-02 20:30:40 -06:00
fix(dir): define "-" (up/parent) mapping earlier #40531
Problem: The dir.lua "-" mapping cannot be easily overridden (because of autocmd ordering). Solution: - Move it to defaults.lua. - Also to be extra polite: fall back to builtin `-` motion if the user disabled the `dir.lua` plugin.
This commit is contained in:
1 parent
3f8be434e1
commit
7325e3b55a
4 files changed
+18
-6
No files matched your search
@@ -149,6 +149,7 @@ you never want any default mappings, call |:mapclear| early in your config.
|
||||
- <C-W> |i_CTRL-W-default|
|
||||
- <C-L> |CTRL-L-default|
|
||||
- & |&-default|
|
||||
- - |dir-mappings|
|
||||
- Q |v_Q-default|
|
||||
- @ |v_@-default|
|
||||
- # |v_#-default|
|
||||
|
||||
@@ -129,6 +129,13 @@ do
|
||||
--- See |&-default|
|
||||
vim.keymap.set('n', '&', ':&&<CR>', { desc = ':help &-default' })
|
||||
|
||||
vim.keymap.set('n', '-', function()
|
||||
if vim.fn.maparg('<Plug>(nvim-dir-up)', 'n') ~= '' then
|
||||
return '<Plug>(nvim-dir-up)'
|
||||
end
|
||||
return (vim.v.count == 0 and '' or vim.v.count) .. '-'
|
||||
end, { expr = true, silent = true, desc = 'Open parent directory' })
|
||||
|
||||
--- Use Q in Visual mode to execute a macro on each line of the selection. #21422
|
||||
--- This only make sense in linewise Visual mode. #28287
|
||||
---
|
||||
|
||||
@@ -18,10 +18,6 @@ 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
|
||||
|
||||
@@ -144,9 +144,9 @@ describe('nvim.dir', function()
|
||||
assert_directory(root)
|
||||
end)
|
||||
|
||||
it('maps - to open the parent directory of the current file', function()
|
||||
it('maps - to open parent directories', function()
|
||||
make_fixture()
|
||||
n.clear({ args_rm = { '-u' } })
|
||||
n.clear({ args_rm = { '-u', '--cmd' } })
|
||||
|
||||
edit(file)
|
||||
feed('-')
|
||||
@@ -154,6 +154,14 @@ describe('nvim.dir', function()
|
||||
|
||||
assert_directory(root)
|
||||
line_of('alpha.txt')
|
||||
|
||||
n.clear({ args_rm = { '--cmd' }, args = { '--noplugin' } })
|
||||
api.nvim_buf_set_lines(0, 0, -1, false, { ' alpha', ' beta' })
|
||||
api.nvim_win_set_cursor(0, { 2, 7 })
|
||||
feed('-')
|
||||
|
||||
eq({ 1, 2 }, api.nvim_win_get_cursor(0))
|
||||
eq(false, exec_lua([[return package.loaded['nvim.dir'] ~= nil]]))
|
||||
end)
|
||||
|
||||
it('uses an absolute buffer name for a relative startup directory argument', function()
|
||||
|
||||
Reference in new issue
Block a user