diff --git a/lua/tree.lua b/lua/tree.lua index 9d278c9ee69..c96551e732e 100644 --- a/lua/tree.lua +++ b/lua/tree.lua @@ -153,6 +153,15 @@ function M.check_windows_and_close() end end +function M.navigate_to_buffer_dir(bufname) + local new_path = get_cwd() + if new_path ~= '/' then + new_path = new_path .. '/' + end + set_root_path(new_path) + init_tree() +end + function M.check_buffer_and_open() local bufname = api.nvim_buf_get_name(0) if bufname == '' then @@ -169,12 +178,7 @@ function M.check_buffer_and_open() M.toggle() else - local new_path = get_cwd() - if new_path ~= '/' then - new_path = new_path .. '/' - end - set_root_path(new_path) - init_tree() + M.navigate_to_buffer_dir() end end diff --git a/plugin/tree.vim b/plugin/tree.vim index 9d1cbcfa10c..af5e2c6a41d 100644 --- a/plugin/tree.vim +++ b/plugin/tree.vim @@ -23,6 +23,7 @@ augroup LuaTree au BufEnter * :LuaTreeFindFile endif + au BufEnter * lua require'tree'.navigate_to_buffer_dir() au ColorScheme * lua require'tree'.reset_highlight() augroup end