diff --git a/doc/nvim-tree-lua.txt b/doc/nvim-tree-lua.txt index 56c5bc9b..5d8382a3 100644 --- a/doc/nvim-tree-lua.txt +++ b/doc/nvim-tree-lua.txt @@ -175,6 +175,7 @@ Subsequent calls to setup will replace the previous configuration. open_on_setup = false, open_on_setup_file = false, open_on_tab = false, + focus_empty_on_setup = false, ignore_buf_on_tab_change = {}, sort_by = "name", root_dirs = {}, @@ -391,6 +392,7 @@ Hijack netrw windows (overridden if |disable_netrw| is `true`) *nvim-tree.open_on_setup* Will automatically open the tree when running setup if startup buffer is a directory, is empty or is unnamed. nvim-tree window will be focused. +See |nvim-tree.focus_empty_on_setup| Type: `boolean`, Default: `false` *nvim-tree.open_on_setup_file* @@ -427,6 +429,11 @@ Opens the tree automatically when switching tabpage or opening a new tabpage if the tree was previously open. Type: `boolean`, Default: `false` +*nvim-tree.focus_empty_on_setup* +When the tree opens as a result of |nvim-tree.open_on_setup| or +|nvim-tree.open_on_tab| and the buffer is empty, focus the buffer. + Type: `boolean`, Default: `false` + *nvim-tree.sort_by* Changes how files within the same directory are sorted. Can be one of `name`, `case_sensitive`, `modification_time`, `extension` or a diff --git a/lua/nvim-tree.lua b/lua/nvim-tree.lua index 99ccff85..40557a76 100644 --- a/lua/nvim-tree.lua +++ b/lua/nvim-tree.lua @@ -244,7 +244,10 @@ function M.on_enter(netrw_disabled) local should_focus_other_window = false local should_find = false if (_config.open_on_setup or _config.open_on_setup_file) and not should_be_preserved then - if buf_is_dir or buf_is_empty then + if buf_is_empty then + should_open = true + should_focus_other_window = _config.focus_empty_on_setup + elseif buf_is_dir then should_open = true elseif is_file and _config.open_on_setup_file then should_open = true @@ -431,6 +434,7 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS open_on_setup = false, open_on_setup_file = false, open_on_tab = false, + focus_empty_on_setup = false, ignore_buf_on_tab_change = {}, sort_by = "name", root_dirs = {}, @@ -704,6 +708,7 @@ function M.setup(conf) _config.update_focused_file = opts.update_focused_file _config.open_on_setup = opts.open_on_setup _config.open_on_setup_file = opts.open_on_setup_file + _config.focus_empty_on_setup = opts.focus_empty_on_setup _config.ignore_buffer_on_setup = opts.ignore_buffer_on_setup _config.ignore_ft_on_setup = opts.ignore_ft_on_setup _config.ignore_buf_on_tab_change = opts.ignore_buf_on_tab_change