From 2a2859412f680b5fc73ae8fdef61d4d97c140d18 Mon Sep 17 00:00:00 2001 From: Yuan Chiu Date: Tue, 29 Apr 2025 14:59:11 +0800 Subject: [PATCH] feat nvim: add terminal --- .../exact_lua/exact_plugins/terminal.lua | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 dot_config/exact_nvim/exact_lua/exact_plugins/terminal.lua diff --git a/dot_config/exact_nvim/exact_lua/exact_plugins/terminal.lua b/dot_config/exact_nvim/exact_lua/exact_plugins/terminal.lua new file mode 100644 index 0000000..bcaffbb --- /dev/null +++ b/dot_config/exact_nvim/exact_lua/exact_plugins/terminal.lua @@ -0,0 +1,44 @@ +return { + { + 'akinsho/toggleterm.nvim', + version = "*", + config = function() + local function is_neo_tree_open() + -- 遍歷所有窗口,檢查是否有窗口對應到 "neo-tree" 緩衝區 + for _, win in ipairs(vim.api.nvim_list_wins()) do + local buf = vim.api.nvim_win_get_buf(win) + if vim.fn.bufname(buf):match("neo%-tree") then + return true -- 找到 NeoTree 窗口 + end + end + return false -- 沒有找到 NeoTree 窗口 + end + + require("toggleterm").setup { + open_mapping = [[]], + on_open = function(_) + if is_neo_tree_open() then + vim.defer_fn(function() + local cmd = string.format("Neotree toggle") + vim.cmd(cmd) + vim.cmd(cmd) + vim.cmd("wincmd p") + end, 100) + end + end, + hide_numbers = true, + shade_filetypes = {}, + shade_terminals = true, + start_in_insert = true, + insert_mappings = true, + persist_size = true, + direction = 'horizontal', + close_on_exit = true, + shell = vim.o.shell, + } + + -- 添加第二個快捷鍵映射 + vim.api.nvim_set_keymap('n', '', 'ToggleTerm', { noremap = true, silent = true }) + end, + }, +}