diff --git a/README.md b/README.md index a3e1f25ea99..4291787379e 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,7 @@ let g:nvim_tree_icon_padding = ' ' "one space by default, used for rendering the 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_create_in_closed_folder = 0 "1 by default, When creating files, sets the path of a file when cursor is on a closed folder to the parent folder when 0, and inside the folder when 1. let g:nvim_tree_refresh_wait = 500 "1000 by default, control how often the tree can be refreshed, 1000 means the tree can be refresh once per 1000ms. let g:nvim_tree_window_picker_exclude = { \ 'filetype': [ diff --git a/doc/nvim-tree-lua.txt b/doc/nvim-tree-lua.txt index 66a433968e9..bba36bb08f5 100644 --- a/doc/nvim-tree-lua.txt +++ b/doc/nvim-tree-lua.txt @@ -349,6 +349,12 @@ WARNING: Behaves strangely with autochdir set. Can be 0 or 1. 0 by default. Will change cwd of nvim-tree to that of new buffer's when opening nvim-tree. +|g:nvim_tree_create_in_closed_folder| *g:nvim_tree_create_in_closed_folder* + +Can be 0 or 1. 1 by default. +Creating a file when the cursor is on a closed folder will set the +path to be inside the closed folder when 1, and on the parent folder when 0. + ============================================================================== INFORMATIONS *nvim-tree-info* diff --git a/lua/nvim-tree/fs.lua b/lua/nvim-tree/fs.lua index 84e3e732b08..e71ecad5849 100644 --- a/lua/nvim-tree/fs.lua +++ b/lua/nvim-tree/fs.lua @@ -57,8 +57,10 @@ function M.create(node) } end + local node_is_open = vim.g.nvim_tree_create_in_closed_folder == 1 or node.open + local add_into - if node.entries ~= nil then + if node.entries ~= nil and node_is_open then add_into = utils.path_add_trailing(node.absolute_path) else add_into = node.absolute_path:sub(0, -(#node.name + 1))