Replace vim-floaterm with toggleterm.nvim

toggleterm provides proper terminal lifecycle management:
- Same <leader>t toggle workflow for floating terminal
- Supports numbered terminals (2<leader>t 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
This commit is contained in:
Aaron Gorodetzky
2026-09-14 10:18:10 -04:00
committed by Aaron Gorodetzky
parent 630c7f5b1f
commit f201970280
2 changed files with 41 additions and 13 deletions
+41
View File
@@ -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 <leader>t (supports count: 2<leader>t opens terminal 2)
vim.keymap.set('n', '<Leader>t', function()
local count = vim.v.count1
require("toggleterm").toggle(count, nil, nil, "float")
end, {silent = true, desc = "Toggle terminal",})
-- In terminal mode: <leader>t closes, <Esc> enters normal mode
vim.keymap.set('t', '<Leader>t', '<Cmd>ToggleTerm<CR>', {silent = true, desc = "Toggle terminal",})
vim.keymap.set('t', '<Esc>', [[<C-\><C-n>]], {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,
}