From dc630d199a0ad593036d193232c6b338aa0407e3 Mon Sep 17 00:00:00 2001 From: kiyan Date: Sat, 28 Aug 2021 11:33:15 +0200 Subject: [PATCH] fix: do not auto open if bufname is and buf has content --- lua/nvim-tree.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lua/nvim-tree.lua b/lua/nvim-tree.lua index badfd2e9..69f592c6 100644 --- a/lua/nvim-tree.lua +++ b/lua/nvim-tree.lua @@ -190,8 +190,10 @@ function M.on_enter() lib.Tree.cwd = vim.fn.expand(bufname) end local netrw_disabled = hijack_netrw == 1 or disable_netrw == 1 + local lines = not is_dir and api.nvim_buf_get_lines(bufnr, 0, -1, false) or {} + local buf_has_content = #lines > 1 or (#lines == 1 and lines[1] ~= "") local should_open = vim.g.nvim_tree_auto_open == 1 - and ((is_dir and netrw_disabled) or bufname == '') + and ((is_dir and netrw_disabled) or (bufname == "" and not buf_has_content)) and not vim.tbl_contains(ft_ignore, buftype) lib.init(should_open, should_open) end