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
|
@ -96,6 +96,9 @@ if vim.g.maplocalleader == "," then
|
||||||
vim.keymap.del("", ",,", { silent = true })
|
vim.keymap.del("", ",,", { silent = true })
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- get out of terminal mode a little easier by double tapping backslash
|
||||||
|
map("t", "\\\\", [[<C-\><C-n>]], { desc = "exit terminal mode" })
|
||||||
|
|
||||||
-- remove search highlights by pressing space+/
|
-- remove search highlights by pressing space+/
|
||||||
map("n", "<leader>/", ":noh<cr>", { desc = "remove highlights" })
|
map("n", "<leader>/", ":noh<cr>", { desc = "remove highlights" })
|
||||||
|
|
||||||
|
@ -252,10 +255,12 @@ map("v", "<localleader>nf", ":ZkMatch<cr>", { desc = "find note from selection"
|
||||||
-- PLUGIN: toggleterm.nvim
|
-- PLUGIN: toggleterm.nvim
|
||||||
-- create a lazygit or python window, set up in toggleterm settings
|
-- create a lazygit or python window, set up in toggleterm settings
|
||||||
-- TODO create ability to go into python environment when in poetry venv and/or euporie/jupyter notebook
|
-- TODO create ability to go into python environment when in poetry venv and/or euporie/jupyter notebook
|
||||||
if require("util").is_available("nvim-toggleterm.lua") then
|
if is_available("nvim-toggleterm.lua") then
|
||||||
map("n", "<leader>G", ":Lazygit<cr>")
|
map("n", "<leader>G", ":Lazygit<cr>")
|
||||||
map("n", "<leader>tg", ":Lazygit<cr>")
|
map("n", "<leader>tg", ":Lazygit<cr>")
|
||||||
|
map("n", "<leader>tG", ":Lazygit!<cr>")
|
||||||
map("n", "<leader>tp", ":Pythonterm<cr>")
|
map("n", "<leader>tp", ":Pythonterm<cr>")
|
||||||
|
map("n", "<leader>tP", ":Pythonterm!<cr>")
|
||||||
end
|
end
|
||||||
|
|
||||||
prefix({ ["<localleader>s"] = { name = "+set" } })
|
prefix({ ["<localleader>s"] = { name = "+set" } })
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
require("toggleterm").setup({
|
require("toggleterm").setup({
|
||||||
open_mapping = [[<leader>=]],
|
open_mapping = [[<leader>=]],
|
||||||
insert_mappings = false, -- don't map the key in insert mode
|
insert_mappings = false, -- don't map the key in insert mode
|
||||||
|
terminal_mappings = false,
|
||||||
})
|
})
|
||||||
|
|
||||||
local Terminal = require("toggleterm.terminal").Terminal
|
local Terminal = require("toggleterm.terminal").Terminal
|
||||||
|
@ -15,15 +16,10 @@ if require("util").is_available("mini.nvim") then
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
-- create a lazygit window with the lazygit command
|
local function custom_term_set_toggle_key(term)
|
||||||
local lazygit = Terminal:new({
|
vim.keymap.set("t", "<C-\\>", function()
|
||||||
cmd = "lazygit",
|
term:toggle()
|
||||||
hidden = true,
|
end, { silent = true, buffer = true })
|
||||||
direction = "float",
|
|
||||||
float_opts = { border = "curved" },
|
|
||||||
})
|
|
||||||
function _Lazygit_toggle()
|
|
||||||
lazygit:toggle()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- create python window
|
-- create python window
|
||||||
|
@ -41,15 +37,49 @@ local function get_python_cmd()
|
||||||
return "python"
|
return "python"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local pythonterm = Terminal:new({
|
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(),
|
cmd = get_python_cmd(),
|
||||||
hidden = true,
|
hidden = true,
|
||||||
direction = "float",
|
direction = "float",
|
||||||
float_opts = { border = "curved" },
|
float_opts = { border = "curved" },
|
||||||
})
|
on_open = custom_term_set_toggle_key,
|
||||||
function _Pythonterm_toggle()
|
}),
|
||||||
pythonterm:toggle()
|
}
|
||||||
|
-- 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
|
end
|
||||||
|
|
||||||
vim.cmd([[command! Lazygit :lua _Lazygit_toggle()<cr>]])
|
local function _Pythonterm_toggle(opts)
|
||||||
vim.cmd([[command! Pythonterm :lua _Pythonterm_toggle()<cr>]])
|
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…
Reference in a new issue