From f201970280e5ded2de601671a183dc472d35ee81 Mon Sep 17 00:00:00 2001 From: Aaron Gorodetzky Date: Mon, 29 Jun 2026 06:17:44 -0400 Subject: [PATCH] Replace vim-floaterm with toggleterm.nvim toggleterm provides proper terminal lifecycle management: - Same t toggle workflow for floating terminal - Supports numbered terminals (2t opens terminal 2) - QuitPre autocmd shuts down all terminals before :qa, preventing the 'terminal has running job' error that blocks quitting - Lua-native, actively maintained --- lua/plugins/floatterm.lua | 13 ------------ lua/plugins/toggleterm.lua | 41 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 13 deletions(-) delete mode 100644 lua/plugins/floatterm.lua create mode 100644 lua/plugins/toggleterm.lua diff --git a/lua/plugins/floatterm.lua b/lua/plugins/floatterm.lua deleted file mode 100644 index 5b90bd5..0000000 --- a/lua/plugins/floatterm.lua +++ /dev/null @@ -1,13 +0,0 @@ -return { - 'voldikss/vim-floaterm', -- Awesome Floating Terminal - config = function() - local map = vim.api.nvim_set_keymap - - -- map('n', 'nt', ':FloatermNew --name=guake --height=0.5 --width=0.5 --autoclose=2 zsh ', {silent = true}) - map('n', 't', ':FloatermToggle guake', {silent = true,}) - - -- Remap terminal mode to quickly close the terminal and allow entering normal mode in the terminal - map('t', 't', ':q', {silent = true,}) - map('t', '', '', {silent = true,}) - end, -} diff --git a/lua/plugins/toggleterm.lua b/lua/plugins/toggleterm.lua new file mode 100644 index 0000000..cf0e1d1 --- /dev/null +++ b/lua/plugins/toggleterm.lua @@ -0,0 +1,41 @@ +return { + 'akinsho/toggleterm.nvim', + version = "*", + config = function() + require("toggleterm").setup({ + open_mapping = false, -- We manage our own mapping below + direction = 'float', + float_opts = { + border = 'rounded', + width = function() return math.floor(vim.o.columns * 0.8) end, + height = function() return math.floor(vim.o.lines * 0.8) end, + }, + shade_terminals = true, + start_in_insert = true, + insert_mappings = false, + terminal_mappings = false, + persist_size = true, + close_on_exit = true, + }) + + -- Toggle terminal with t (supports count: 2t opens terminal 2) + vim.keymap.set('n', 't', function() + local count = vim.v.count1 + require("toggleterm").toggle(count, nil, nil, "float") + end, {silent = true, desc = "Toggle terminal",}) + + -- In terminal mode: t closes, enters normal mode + vim.keymap.set('t', 't', 'ToggleTerm', {silent = true, desc = "Toggle terminal",}) + vim.keymap.set('t', '', [[]], {silent = true,}) + + -- Close all terminals before quitting to prevent :qa errors + vim.api.nvim_create_autocmd('QuitPre', { + callback = function() + local terms = require("toggleterm.terminal").get_all() + for _, term in ipairs(terms) do + term:shutdown() + end + end, + }) + end, +}