Skip to content

Commit 351a3e9

Browse files
committed
feat: added prevent_buffer_override option to allow in-place opens by :e
1 parent 75c0574 commit 351a3e9

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

doc/nvim-tree-lua.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,7 @@ applying configuration.
494494
},
495495
open_file = {
496496
quit_on_open = false,
497+
prevent_buffer_override = true,
497498
resize_window = true,
498499
window_picker = {
499500
enable = true,
@@ -1203,9 +1204,12 @@ Configuration for various actions.
12031204

12041205
*nvim-tree.actions.open_file.quit_on_open*
12051206
Closes the explorer when opening a file.
1206-
It will also disable preventing a buffer overriding the tree.
12071207
Type: `boolean`, Default: `false`
12081208

1209+
*nvim-tree.actions.open_file.prevent_buffer_override*
1210+
Prevent new opened file from opening in the same window as the tree.
1211+
Type: `boolean`, Default: `true`
1212+
12091213
*nvim-tree.actions.open_file.resize_window* (previously `view.auto_resize`)
12101214
Resizes the tree when opening a file.
12111215
Type: `boolean`, Default: `true`

lua/nvim-tree.lua

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -192,15 +192,17 @@ local function setup_autocommands(opts)
192192
-- reset highlights when colorscheme is changed
193193
create_nvim_tree_autocmd("ColorScheme", { callback = M.reset_highlight })
194194

195-
-- prevent new opened file from opening in the same window as nvim-tree
196-
create_nvim_tree_autocmd("BufWipeout", {
197-
pattern = "NvimTree_*",
198-
callback = function()
199-
if utils.is_nvim_tree_buf(0) then
200-
view._prevent_buffer_override()
201-
end
202-
end,
203-
})
195+
if opts.actions.open_file.prevent_buffer_override then
196+
-- prevent new opened file from opening in the same window as nvim-tree
197+
create_nvim_tree_autocmd("BufWipeout", {
198+
pattern = "NvimTree_*",
199+
callback = function()
200+
if utils.is_nvim_tree_buf(0) then
201+
view._prevent_buffer_override()
202+
end
203+
end,
204+
})
205+
end
204206

205207
create_nvim_tree_autocmd("BufWritePost", {
206208
callback = function()
@@ -545,6 +547,7 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
545547
},
546548
open_file = {
547549
quit_on_open = false,
550+
prevent_buffer_override = true,
548551
resize_window = true,
549552
window_picker = {
550553
enable = true,

0 commit comments

Comments
 (0)