From bd049adb9a6b6fcd048129cf640685729bbc96b8 Mon Sep 17 00:00:00 2001 From: Colin Graydon Date: Mon, 7 Apr 2025 22:27:56 -0400 Subject: [PATCH] feat: add terminal toggle --- lua/config/keymaps.lua | 45 +++++++++++++++++++++++++++++++++++++ lua/plugins/colorscheme.lua | 15 ------------- 2 files changed, 45 insertions(+), 15 deletions(-) diff --git a/lua/config/keymaps.lua b/lua/config/keymaps.lua index 0257a42..040d509 100644 --- a/lua/config/keymaps.lua +++ b/lua/config/keymaps.lua @@ -4,6 +4,51 @@ vim.keymap.set("n", "", ":w", { desc = "Save file", silent = true }) vim.keymap.set("i", "", ":wa", { desc = "Save file", silent = true }) vim.g.neovide_input_macos_option_key_is_meta = "only_left" + +vim.api.nvim_echo({ { "Terminal toggle binding loaded!", "Normal" } }, true, {}) +-- Terminal keybindings with Ctrl+` +vim.keymap.set({ "n", "t" }, "", function() + local term_bufnrs = {} + for _, bufnr in ipairs(vim.api.nvim_list_bufs()) do + if vim.bo[bufnr].buftype == "terminal" then + table.insert(term_bufnrs, bufnr) + end + end + + if #term_bufnrs == 0 then + -- No terminal exists, create a new one + vim.cmd("split | terminal") + vim.cmd("resize 15") + vim.cmd("startinsert") + else + -- Check if a terminal is visible + local term_visible = false + for _, win in ipairs(vim.api.nvim_list_wins()) do + local buf = vim.api.nvim_win_get_buf(win) + if vim.bo[buf].buftype == "terminal" then + term_visible = true + if vim.api.nvim_get_current_win() == win then + -- Currently focused on terminal, hide it + vim.cmd("hide") + else + -- Terminal visible but not focused, focus it + vim.api.nvim_set_current_win(win) + vim.cmd("startinsert") + end + break + end + end + + if not term_visible then + -- Terminal exists but not visible, show it + vim.cmd("sbuffer " .. term_bufnrs[1]) + vim.cmd("resize 15") + vim.cmd("startinsert") + end + end +end, { desc = "Toggle terminal" }) + +-- Neovide enable Command key if vim.g.neovide then -- Enable Command key mappings vim.g.neovide_input_use_logo = true -- Enable the Command/Super/Windows key diff --git a/lua/plugins/colorscheme.lua b/lua/plugins/colorscheme.lua index 2f73799..b2cd850 100644 --- a/lua/plugins/colorscheme.lua +++ b/lua/plugins/colorscheme.lua @@ -1,24 +1,9 @@ --- In ~/.config/nvim/lua/plugins/colorscheme.lua return { -- Add Dracula colorscheme { "Mofiqul/dracula.nvim", lazy = false, priority = 1000, - config = function() - -- First load the colorscheme - vim.cmd([[colorscheme dracula]]) - - -- Then override the problematic highlight groups - vim.api.nvim_set_hl(0, "NeoTreeDirectoryName", { fg = "#BD93F9" }) -- Purple for directories - vim.api.nvim_set_hl(0, "NeoTreeDirectoryIcon", { fg = "#BD93F9" }) - vim.api.nvim_set_hl(0, "NeoTreeNormal", { fg = "#F8F8F2" }) -- Lighter text - - -- For NvimTree (if you're using that instead) - vim.api.nvim_set_hl(0, "NvimTreeFolderName", { fg = "#BD93F9" }) - vim.api.nvim_set_hl(0, "NvimTreeFolderIcon", { fg = "#BD93F9" }) - vim.api.nvim_set_hl(0, "NvimTreeNormal", { fg = "#F8F8F2" }) - end, }, -- Configure LazyVim to use Dracula