Skip to content

feat: reload explorer on buf enter #1265

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 4 commits into from
May 17, 2022
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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ require'nvim-tree'.setup { -- BEGIN_DEFAULT_OPTS
open_on_tab = false,
sort_by = "name",
update_cwd = false,
reload_on_bufenter = false,
view = {
width = 30,
height = 30,
Expand Down Expand Up @@ -156,7 +157,7 @@ require'nvim-tree'.setup { -- BEGIN_DEFAULT_OPTS
icons = {
webdev_colors = true,
git_placement = "before",
}
},
},
hijack_directories = {
enable = true,
Expand Down
7 changes: 6 additions & 1 deletion doc/nvim-tree-lua.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ Values may be functions. Warning: this may result in unexpected behaviour.
open_on_tab = false,
sort_by = "name",
update_cwd = false,
reload_on_bufenter = false,
view = {
width = 30,
height = 30,
Expand Down Expand Up @@ -124,7 +125,7 @@ Values may be functions. Warning: this may result in unexpected behaviour.
icons = {
webdev_colors = true,
git_placement = "before",
}
},
},
hijack_directories = {
enable = true,
Expand Down Expand Up @@ -259,6 +260,10 @@ Keeps the cursor on the first letter of the filename when moving in the tree.
Changes the tree root directory on `DirChanged` and refreshes the tree.
Type: `boolean`, Default: `false`

*nvim-tree.reload_on_bufenter*
Automatically reloads the tree on `BufEnter` nvim-tree.
Type: `boolean`, Default: `false`

*nvim-tree.hijack_directories*
hijacks new directory buffers when they are opened (`:e dir`).

Expand Down
5 changes: 5 additions & 0 deletions lua/nvim-tree.lua
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,10 @@ local function setup_autocommands(opts)
if opts.hijack_directories.enable then
create_nvim_tree_autocmd({ "BufEnter", "BufNewFile" }, { callback = M.open_on_directory })
end

if opts.reload_on_bufenter then
create_nvim_tree_autocmd("BufEnter", { pattern = "NvimTree_*", callback = reloaders.reload_explorer })
end
end

local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
Expand All @@ -350,6 +354,7 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
open_on_tab = false,
sort_by = "name",
update_cwd = false,
reload_on_bufenter = false,
view = {
width = 30,
height = 30,
Expand Down