Add a sticky terminal panel to the bottom, remove old terminal from lspsaga

This commit is contained in:
Martin Larsson 2024-05-26 23:10:44 +02:00
parent 49ad4d1bad
commit d4126dc480
5 changed files with 59 additions and 9 deletions

View file

@ -28,5 +28,8 @@ require("lazy_init")
-- Initialize plugins, add a plugin by creating a new file in the plugins dir -- Initialize plugins, add a plugin by creating a new file in the plugins dir
require("lazy").setup("plugs") require("lazy").setup("plugs")
-- Initialize the sticky terminal window at the bottom
require("terminal").setup()
-- See ":help vim.highlight.on_yank()" -- See ":help vim.highlight.on_yank()"
setup_yank_highlight() setup_yank_highlight()

View file

@ -118,11 +118,5 @@ require("utils").add_keymaps({
["<C-x>"] = { ["<C-x>"] = {
cmd = "<C-\\><C-N>", cmd = "<C-\\><C-N>",
}, },
["<Esc>"] = {
cmd = function()
local win = vim.api.nvim_get_current_win()
vim.api.nvim_win_close(win, true)
end,
}
}, },
}) })

View file

@ -46,9 +46,6 @@ return {
["<leader>rn"] = { ["<leader>rn"] = {
cmd = ":Lspsaga rename<CR>" cmd = ":Lspsaga rename<CR>"
}, },
["<leader>h"] = {
cmd = ":Lspsaga term_toggle<CR>"
},
["gr"] = { ["gr"] = {
cmd = ":Lspsaga finder<CR>" cmd = ":Lspsaga finder<CR>"
}, },

View file

@ -0,0 +1,52 @@
local utils = require("utils")
local M = {}
local terminal_window = nil
local terminal_bufnr = nil
local function open_terminal_window()
if terminal_bufnr and vim.api.nvim_buf_is_valid(terminal_bufnr) and utils.is_buf_buftype(terminal_bufnr, "terminal") then
vim.cmd("botright split")
terminal_window = vim.api.nvim_get_current_win()
vim.api.nvim_win_set_buf(terminal_window, terminal_bufnr)
else
vim.cmd("botright split term://zsh")
terminal_window = vim.api.nvim_get_current_win()
terminal_bufnr = vim.api.nvim_get_current_buf()
end
end
local function toggle_terminal()
if terminal_window and vim.api.nvim_win_is_valid(terminal_window) then
vim.api.nvim_win_close(terminal_window, true)
terminal_window = nil
return
end
open_terminal_window()
local term_height = vim.api.nvim_get_option("lines")
local height_percentage = 0.225
local min_height = 15
local max_height = 25
local height = utils.calculate_split_size(term_height, height_percentage, min_height, max_height)
vim.api.nvim_win_set_height(terminal_window, height)
vim.api.nvim_win_set_option(terminal_window, "winfixheight", true)
vim.api.nvim_win_set_option(terminal_window, "winhighlight", "Normal:Utility,FloatBorder:Utility")
utils.lock_buf_to_window(terminal_window, terminal_bufnr, "terminal")
vim.api.nvim_command("startinsert")
end
function M.setup()
utils.add_keymaps({
n = {
["<leader>h"] = {
cmd = toggle_terminal
}
}
})
end
return M

View file

@ -12,6 +12,10 @@ function M.is_buf_filetype(bufnr, filetype)
return vim.api.nvim_buf_get_option(bufnr, "filetype") == filetype return vim.api.nvim_buf_get_option(bufnr, "filetype") == filetype
end end
function M.is_buf_buftype(bufnr, filetype)
return vim.api.nvim_buf_get_option(bufnr, "buftype") == filetype
end
function M.lock_buf_to_window(win_id, bufnr, filetype) function M.lock_buf_to_window(win_id, bufnr, filetype)
local augroup_id = vim.api.nvim_create_augroup("LockWindow" .. win_id, { clear = true }) local augroup_id = vim.api.nvim_create_augroup("LockWindow" .. win_id, { clear = true })