nvim: Move toggleterm out of core plugins
Toggleterm, as nice as it is, is not one of my core dependencies. I do not 'need' toggleterm on every nvim installation I have. Instead, it can go into ui-related plugins since that is what it does, extend nvim's UI functionality with new terminal dropdowns/floats.
This commit is contained in:
parent
9fb1f958e6
commit
7c37baa565
3 changed files with 102 additions and 100 deletions
|
@ -1,85 +0,0 @@
|
||||||
require("toggleterm").setup({
|
|
||||||
open_mapping = [[<leader>=]],
|
|
||||||
insert_mappings = false, -- don't map the key in insert mode
|
|
||||||
terminal_mappings = false,
|
|
||||||
})
|
|
||||||
|
|
||||||
local Terminal = require("toggleterm.terminal").Terminal
|
|
||||||
|
|
||||||
-- need to disable indentlines since they obscure first line of terminal
|
|
||||||
if require("util").is_available("mini.nvim") then
|
|
||||||
vim.api.nvim_create_autocmd({ "TermOpen" }, {
|
|
||||||
pattern = "*",
|
|
||||||
callback = function()
|
|
||||||
vim.b.miniindentscope_disable = true
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
end
|
|
||||||
|
|
||||||
local function custom_term_set_toggle_key(term)
|
|
||||||
vim.keymap.set("t", "<C-\\>", function()
|
|
||||||
term:toggle()
|
|
||||||
end, { silent = true, buffer = true })
|
|
||||||
end
|
|
||||||
|
|
||||||
-- create python window
|
|
||||||
local function get_python_cmd()
|
|
||||||
if vim.fn.executable("ptipython") then
|
|
||||||
return "ptipython"
|
|
||||||
end
|
|
||||||
if vim.fn.executable("ipython") then
|
|
||||||
return "ipython"
|
|
||||||
end
|
|
||||||
if vim.fn.executable("ptpython") then
|
|
||||||
return "ptpython"
|
|
||||||
end
|
|
||||||
if vim.fn.executable("python") then
|
|
||||||
return "python"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
local terms = {
|
|
||||||
lazygit = Terminal:new({
|
|
||||||
cmd = "lazygit",
|
|
||||||
hidden = true,
|
|
||||||
direction = "float",
|
|
||||||
float_opts = { border = "curved" },
|
|
||||||
on_open = custom_term_set_toggle_key,
|
|
||||||
}),
|
|
||||||
python = Terminal:new({
|
|
||||||
cmd = get_python_cmd(),
|
|
||||||
hidden = true,
|
|
||||||
direction = "float",
|
|
||||||
float_opts = { border = "curved" },
|
|
||||||
on_open = custom_term_set_toggle_key,
|
|
||||||
}),
|
|
||||||
}
|
|
||||||
-- create a lazygit window with the lazygit command
|
|
||||||
local function toggle_custom_term(term, bang, vertsize)
|
|
||||||
vertsize = vertsize or vim.o.columns * 0.4
|
|
||||||
if not bang then
|
|
||||||
term.direction = "float"
|
|
||||||
term:toggle()
|
|
||||||
else
|
|
||||||
term.direction = "vertical"
|
|
||||||
term:resize(vertsize)
|
|
||||||
term:toggle()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local function _Pythonterm_toggle(opts)
|
|
||||||
toggle_custom_term(terms.python, opts.bang)
|
|
||||||
end
|
|
||||||
local function _Lazygit_toggle(opts)
|
|
||||||
toggle_custom_term(terms.lazygit, opts.bang, vim.o.columns * 0.6)
|
|
||||||
end
|
|
||||||
|
|
||||||
vim.api.nvim_create_user_command(
|
|
||||||
"Lazygit",
|
|
||||||
_Lazygit_toggle,
|
|
||||||
{ desc = "Toggle floating Lazygit terminal", bang = true }
|
|
||||||
)
|
|
||||||
vim.api.nvim_create_user_command(
|
|
||||||
"Pythonterm",
|
|
||||||
_Pythonterm_toggle,
|
|
||||||
{ desc = "Toggle floating Python terminal", bang = true }
|
|
||||||
)
|
|
|
@ -73,20 +73,6 @@ return {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
-- simpler, programmable and multiple terminal toggling for nvim
|
|
||||||
{
|
|
||||||
"akinsho/nvim-toggleterm.lua",
|
|
||||||
config = function()
|
|
||||||
require("plugins.config.toggleterm")
|
|
||||||
end,
|
|
||||||
cmd = { "ToggleTerm", "TermExec", "Lazygit", "Pythonterm" },
|
|
||||||
keys = {
|
|
||||||
{ "<leader>sg", ":Lazygit<cr>" },
|
|
||||||
{ "<leader>sG", ":Lazygit!<cr>" },
|
|
||||||
{ "<leader>sp", ":Pythonterm<cr>" },
|
|
||||||
{ "<leader>sP", ":Pythonterm!<cr>" },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
-- try to avoid putting files in util buffers, e.g. filetree, aerial, undotree, ..
|
-- try to avoid putting files in util buffers, e.g. filetree, aerial, undotree, ..
|
||||||
{ "stevearc/stickybuf.nvim", config = true },
|
{ "stevearc/stickybuf.nvim", config = true },
|
||||||
-- make it a little less painful to open really big (>2mb) files by disabling features
|
-- make it a little less painful to open really big (>2mb) files by disabling features
|
||||||
|
|
|
@ -45,7 +45,7 @@ return {
|
||||||
override_vim_notify = true,
|
override_vim_notify = true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
event = "VimEnter",
|
event = { "VeryLazy" },
|
||||||
},
|
},
|
||||||
-- make all vim.ui interfaces prettyy
|
-- make all vim.ui interfaces prettyy
|
||||||
{ "stevearc/dressing.nvim", config = true, event = "VeryLazy" },
|
{ "stevearc/dressing.nvim", config = true, event = "VeryLazy" },
|
||||||
|
@ -111,4 +111,105 @@ return {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
-- simpler, programmable and multiple terminal toggling for nvim
|
||||||
|
{
|
||||||
|
"akinsho/nvim-toggleterm.lua",
|
||||||
|
config = function()
|
||||||
|
require("toggleterm").setup({
|
||||||
|
open_mapping = [[<leader>=]],
|
||||||
|
insert_mappings = false, -- don't map the key in insert mode
|
||||||
|
terminal_mappings = false,
|
||||||
|
})
|
||||||
|
|
||||||
|
local Terminal = require("toggleterm.terminal").Terminal
|
||||||
|
|
||||||
|
-- need to disable indentlines since they obscure first line of terminal
|
||||||
|
if require("util").is_available("mini.nvim") then
|
||||||
|
vim.api.nvim_create_autocmd({ "TermOpen" }, {
|
||||||
|
pattern = "*",
|
||||||
|
callback = function()
|
||||||
|
vim.b.miniindentscope_disable = true
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
local function custom_term_set_toggle_key(term)
|
||||||
|
vim.keymap.set("t", "<C-\\>", function()
|
||||||
|
term:toggle()
|
||||||
|
end, { silent = true, buffer = true })
|
||||||
|
end
|
||||||
|
|
||||||
|
-- create python window
|
||||||
|
local function get_python_cmd()
|
||||||
|
if vim.fn.executable("py") then
|
||||||
|
return "py"
|
||||||
|
end
|
||||||
|
if vim.fn.executable("ptipython") then
|
||||||
|
return "ptipython"
|
||||||
|
end
|
||||||
|
if vim.fn.executable("ipython") then
|
||||||
|
return "ipython"
|
||||||
|
end
|
||||||
|
if vim.fn.executable("ptpython") then
|
||||||
|
return "ptpython"
|
||||||
|
end
|
||||||
|
if vim.fn.executable("python") then
|
||||||
|
return "python"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local terms = {
|
||||||
|
lazygit = Terminal:new({
|
||||||
|
cmd = "lazygit",
|
||||||
|
hidden = true,
|
||||||
|
direction = "float",
|
||||||
|
float_opts = { border = "curved" },
|
||||||
|
on_open = custom_term_set_toggle_key,
|
||||||
|
}),
|
||||||
|
python = Terminal:new({
|
||||||
|
cmd = get_python_cmd(),
|
||||||
|
hidden = true,
|
||||||
|
direction = "float",
|
||||||
|
float_opts = { border = "curved" },
|
||||||
|
on_open = custom_term_set_toggle_key,
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
-- create a lazygit window with the lazygit command
|
||||||
|
local function toggle_custom_term(term, bang, vertsize)
|
||||||
|
vertsize = vertsize or vim.o.columns * 0.4
|
||||||
|
if not bang then
|
||||||
|
term.direction = "float"
|
||||||
|
term:toggle()
|
||||||
|
else
|
||||||
|
term.direction = "vertical"
|
||||||
|
term:resize(vertsize)
|
||||||
|
term:toggle()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function _Pythonterm_toggle(opts)
|
||||||
|
toggle_custom_term(terms.python, opts.bang)
|
||||||
|
end
|
||||||
|
local function _Lazygit_toggle(opts)
|
||||||
|
toggle_custom_term(terms.lazygit, opts.bang, vim.o.columns * 0.6)
|
||||||
|
end
|
||||||
|
|
||||||
|
vim.api.nvim_create_user_command(
|
||||||
|
"Lazygit",
|
||||||
|
_Lazygit_toggle,
|
||||||
|
{ desc = "Toggle floating Lazygit terminal", bang = true }
|
||||||
|
)
|
||||||
|
vim.api.nvim_create_user_command(
|
||||||
|
"Pythonterm",
|
||||||
|
_Pythonterm_toggle,
|
||||||
|
{ desc = "Toggle floating Python terminal", bang = true }
|
||||||
|
)
|
||||||
|
end,
|
||||||
|
cmd = { "ToggleTerm", "TermExec", "Lazygit", "Pythonterm" },
|
||||||
|
keys = {
|
||||||
|
{ "<leader>sg", ":Lazygit<cr>", desc = "git floating" },
|
||||||
|
{ "<leader>sG", ":Lazygit!<cr>", desc = "git buffer" },
|
||||||
|
{ "<leader>sp", ":Pythonterm<cr>", desc = "python floating" },
|
||||||
|
{ "<leader>sP", ":Pythonterm!<cr>", desc = "python buffer" },
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue