From 143505b281ca136c55d4f038c9e539a736bfc5f0 Mon Sep 17 00:00:00 2001 From: Yusuke Uchida <51429010+ucchiee@users.noreply.github.com> Date: Sat, 7 Aug 2021 16:59:42 +0900 Subject: [PATCH] Added new option, respect_buf_cwd (#533) --- README.md | 1 + doc/nvim-tree-lua.txt | 5 +++++ lua/nvim-tree/lib.lua | 6 ++++-- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b3a4fa99..5283cafd 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,7 @@ let g:nvim_tree_hijack_cursor = 0 "1 by default, when moving cursor in the tree, let g:nvim_tree_icon_padding = ' ' "one space by default, used for rendering the space between the icon and the filename. Use with caution, it could break rendering if you set an empty string depending on your font. let g:nvim_tree_symlink_arrow = ' >> ' " defaults to ' ➛ '. used as a separator between symlinks' source and target. let g:nvim_tree_update_cwd = 1 "0 by default, will update the tree cwd when changing nvim's directory (DirChanged event). Behaves strangely with autochdir set. +let g:nvim_tree_respect_buf_cwd = 1 "0 by default, will change cwd of nvim-tree to that of new buffer's when opening nvim-tree. let g:nvim_tree_window_picker_exclude = { \ 'filetype': [ \ 'packer', diff --git a/doc/nvim-tree-lua.txt b/doc/nvim-tree-lua.txt index 07a80b55..5768961f 100644 --- a/doc/nvim-tree-lua.txt +++ b/doc/nvim-tree-lua.txt @@ -320,6 +320,11 @@ Can be 0 or 1. 0 by default. Will update the tree cwd when changing nvim's directory (DirChanged event). WARNING: Behaves strangely with autochdir set. +|g:nvim_tree_respect_buf_cwd| *g:nvim_tree_respect_buf_cwd* + +Can be 0 or 1. 0 by default. +Will change cwd of nvim-tree to that of new buffer's when opening nvim-tree. + ============================================================================== INFORMATIONS *nvim-tree-info* diff --git a/lua/nvim-tree/lib.lua b/lua/nvim-tree/lib.lua index e4fefb6d..d726a21b 100644 --- a/lua/nvim-tree/lib.lua +++ b/lua/nvim-tree/lib.lua @@ -466,8 +466,10 @@ function M.open() view.open() - if M.Tree.loaded then - M.change_dir(vim.fn.getcwd()) + local cwd = vim.fn.getcwd() + local respect_buf_cwd = vim.g.nvim_tree_respect_buf_cwd or 0 + if M.Tree.loaded or (respect_buf_cwd == 1 and cwd ~= M.Tree.cwd) then + M.change_dir(cwd) end renderer.draw(M.Tree, not M.Tree.loaded) M.Tree.loaded = true