Skip to content

feat: option to set path destination to parent folder when cursor is on a closed folder while creating files #628

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Sep 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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': [
Expand Down
6 changes: 6 additions & 0 deletions doc/nvim-tree-lua.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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*

Expand Down
4 changes: 3 additions & 1 deletion lua/nvim-tree/fs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down