nvim: Make utility terminals dockable and hidable
The utility terminals (lazygit and python repl for now) can now be hidden even from terminal insert mode (i.e. when interacting with them) with <C-\>. They can be invoked through their usual chords (<leader>tg and <leader>tp respectively) again and will pick right up where you left off. Insert mode in terminals can also be left slightly easier should it be needed: Instead of the <C-\><C-n> chord you can use j\. Lastly, the utility terminals can be started in a vertically docked mode instead of floating. This is done by adding a bang to their commands, `Lazygit!` and `Pythonterm!`, or using capital versions of their mappings: <leader>tG and <leader>tP.
This commit is contained in:
parent
b9de8b3914
commit
ca3d4ef97b
2 changed files with 55 additions and 20 deletions
|
|
@ -1,6 +1,7 @@
|
|||
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
|
||||
|
|
@ -15,15 +16,10 @@ if require("util").is_available("mini.nvim") then
|
|||
})
|
||||
end
|
||||
|
||||
-- create a lazygit window with the lazygit command
|
||||
local lazygit = Terminal:new({
|
||||
cmd = "lazygit",
|
||||
hidden = true,
|
||||
direction = "float",
|
||||
float_opts = { border = "curved" },
|
||||
})
|
||||
function _Lazygit_toggle()
|
||||
lazygit:toggle()
|
||||
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
|
||||
|
|
@ -41,15 +37,49 @@ local function get_python_cmd()
|
|||
return "python"
|
||||
end
|
||||
end
|
||||
local pythonterm = Terminal:new({
|
||||
cmd = get_python_cmd(),
|
||||
hidden = true,
|
||||
direction = "float",
|
||||
float_opts = { border = "curved" },
|
||||
})
|
||||
function _Pythonterm_toggle()
|
||||
pythonterm:toggle()
|
||||
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
|
||||
|
||||
vim.cmd([[command! Lazygit :lua _Lazygit_toggle()<cr>]])
|
||||
vim.cmd([[command! Pythonterm :lua _Pythonterm_toggle()<cr>]])
|
||||
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 }
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue