fix nvim: 先暫時關閉tab開啟neo-tree功能

This commit is contained in:
Yuan Chiu 2025-04-29 11:49:09 +08:00
parent 8629364fd9
commit 0b94b839d9

View File

@ -422,31 +422,32 @@ return {
end, end,
}) })
-- 自動命令:當進入緩衝區(開啟文件)時自動顯示 Neo-tree -- -- 自動命令:當進入緩衝區(開啟文件)時自動顯示 Neo-tree
vim.api.nvim_create_autocmd("BufEnter", { -- -- PS. 在neo-tree做`:q`關閉時會報錯crash。先關閉此功能
callback = function() -- vim.api.nvim_create_autocmd("BufEnter", {
-- 檢查是否為普通文件類型,避免在特殊緩衝區(如 terminal 或 quickfix中啟動 -- callback = function()
local buf_ft = vim.bo.filetype -- -- 檢查是否為普通文件類型,避免在特殊緩衝區(如 terminal 或 quickfix中啟動
if buf_ft ~= "neo-tree" and buf_ft ~= "terminal" and buf_ft ~= "quickfix" then -- local buf_ft = vim.bo.filetype
-- 確保當前分頁是否已經有 Neo-tree -- if buf_ft ~= "neo-tree" and buf_ft ~= "terminal" and buf_ft ~= "quickfix" then
local neo_tree_open = false -- -- 確保當前分頁是否已經有 Neo-tree
for _, win in ipairs(vim.api.nvim_tabpage_list_wins(0)) do -- local neo_tree_open = false
local buf = vim.api.nvim_win_get_buf(win) -- for _, win in ipairs(vim.api.nvim_tabpage_list_wins(0)) do
if vim.api.nvim_buf_get_option(buf, "filetype") == "neo-tree" then -- local buf = vim.api.nvim_win_get_buf(win)
neo_tree_open = true -- if vim.api.nvim_buf_get_option(buf, "filetype") == "neo-tree" then
break -- neo_tree_open = true
end -- break
end -- end
-- end
-- 如果當前分頁沒有 Neo-tree則打開 -- -- 如果當前分頁沒有 Neo-tree則打開
if not neo_tree_open then -- if not neo_tree_open then
vim.cmd("Neotree show") -- vim.cmd("Neotree show")
vim.cmd("Neotree reveal") -- vim.cmd("Neotree reveal")
vim.cmd("wincmd p") -- 將焦點切回到之前的窗口 -- vim.cmd("wincmd p") -- 將焦點切回到之前的窗口
end -- end
end -- end
end, -- end,
}) -- })
end, end,
}, },
} }