main
Dominik Madarász 2024-11-14 19:17:51 +01:00
parent b506c9f1b0
commit 1af52240b3
1 changed files with 33 additions and 29 deletions

View File

@ -20,6 +20,36 @@ vim.keymap.set("n", "<A-m>", "<C-6>")
vim.keymap.set("t", "<Esc>", "<C-\\><C-n>", { noremap = true, silent = true })
-- vim.keymap.set("n", "<leader>;", ":vsplit term://left<CR><A-Right><CR>", { noremap = true, silent = true })
vim.g.is_maximized = false
vim.g.original_height = 0
vim.g.original_width = 0
function ToggleZen()
if vim.g.is_maximized then
-- Restore original size
if vim.g.original_height > 0 then vim.cmd('resize ' .. vim.g.original_height) end
if vim.g.original_width > 0 then vim.cmd('vertical resize ' .. vim.g.original_width) end
vim.g.is_maximized = false
else
-- Save current dimensions
vim.g.original_height = vim.fn.winheight(0)
vim.g.original_width = vim.fn.winwidth(0)
-- Check if the buffer is a terminal
if vim.bo.buftype == "terminal" then
-- Maximize height only
vim.cmd('resize')
else
-- Maximize both height and width
vim.cmd('resize')
vim.cmd('vertical resize')
end
vim.g.is_maximized = true
end
end
local term_buf = nil
function toggleTerminal()
@ -27,6 +57,7 @@ function toggleTerminal()
if term_buf and vim.api.nvim_buf_is_valid(term_buf) then
-- If the terminal is open in the current window, hide it
if vim.api.nvim_get_current_buf() == term_buf then
ToggleZen()
vim.cmd("close")
vim.cmd("wincmd w")
else
@ -35,6 +66,7 @@ function toggleTerminal()
vim.cmd("belowright split | resize " .. math.floor(vim.o.lines * 0.25))
vim.api.nvim_set_current_buf(term_buf)
vim.cmd("startinsert")
ToggleZen()
end
else
-- If no terminal buffer exists, create a new one
@ -43,6 +75,7 @@ function toggleTerminal()
vim.cmd("terminal")
vim.cmd("startinsert")
term_buf = vim.api.nvim_get_current_buf() -- Store the terminal buffer ID
ToggleZen()
end -- Check if the current buffer is a terminal
end
@ -146,35 +179,6 @@ vim.keymap.set('n', '<leader>cd', function()
vim.cmd('Ex ' .. config_dir)
end, { desc = 'Jump to Neovim config directory' })
vim.g.is_maximized = false
vim.g.original_height = 0
vim.g.original_width = 0
function ToggleZen()
if vim.g.is_maximized then
-- Restore original size
if vim.g.original_height > 0 then vim.cmd('resize ' .. vim.g.original_height) end
if vim.g.original_width > 0 then vim.cmd('vertical resize ' .. vim.g.original_width) end
vim.g.is_maximized = false
else
-- Save current dimensions
vim.g.original_height = vim.fn.winheight(0)
vim.g.original_width = vim.fn.winwidth(0)
-- Check if the buffer is a terminal
if vim.bo.buftype == "terminal" then
-- Maximize height only
vim.cmd('resize')
else
-- Maximize both height and width
vim.cmd('resize')
vim.cmd('vertical resize')
end
vim.g.is_maximized = true
end
end
vim.keymap.set('n', '<A-z>', ToggleZen, { desc = 'Zen Mode' })
vim.keymap.set('v', '<A-z>', ToggleZen, { desc = 'Zen Mode' })
vim.keymap.set('i', '<A-z>', ToggleZen, { desc = 'Zen Mode' })