diff --git a/runtime/doc/plugins.txt b/runtime/doc/plugins.txt index 5d2dc30c34..c0df7881be 100644 --- a/runtime/doc/plugins.txt +++ b/runtime/doc/plugins.txt @@ -48,8 +48,12 @@ Builtin plugin: dir *dir* Nvim opens a directory listing when |:edit| is used with a directory path. The listing is a buffer with 'filetype' set to "directory". -To disable the built-in directory browser, delete its autocommand group from an -after/plugin file: >lua + *g:loaded_nvim_dir_plugin* +To disable the built-in directory browser, set this before startup: >lua + vim.g.loaded_nvim_dir_plugin = 1 +< + +To delete only its directory-opening autocommands from an after/plugin file: >lua vim.api.nvim_del_augroup_by_name('nvim.dir') < diff --git a/runtime/plugin/dir.lua b/runtime/plugin/dir.lua index bc05cd646d..85f3b9e6a1 100644 --- a/runtime/plugin/dir.lua +++ b/runtime/plugin/dir.lua @@ -1,3 +1,8 @@ +if vim.g.loaded_nvim_dir_plugin ~= nil then + return +end +vim.g.loaded_nvim_dir_plugin = true + local api = vim.api local nvim_on = require('vim._core.util').nvim_on diff --git a/test/functional/plugin/dir_spec.lua b/test/functional/plugin/dir_spec.lua index e91bdc11c0..9bd98fac0d 100644 --- a/test/functional/plugin/dir_spec.lua +++ b/test/functional/plugin/dir_spec.lua @@ -364,7 +364,7 @@ describe('nvim.dir', function() eq('', api.nvim_get_option_value('filetype', { buf = 0 })) end) - it('coexists with netrw', function() + it('coexists with netrw and can be disabled', function() if t.is_zig_build() then return pending('broken with build.zig relative runtime paths after chdir') end @@ -380,6 +380,13 @@ describe('nvim.dir', function() command('Explore .') cd(cwd) eq('netrw', api.nvim_get_option_value('filetype', { buf = 0 })) + + n.clear({ + args_rm = { '-u' }, + args = { '--cmd', 'let g:loaded_nvim_dir_plugin = 1' }, + }) + edit(root) + eq('netrw', api.nvim_get_option_value('filetype', { buf = 0 })) end) it('supports the FileExplorer browse contract', function()