From 19b489e531650e84d85eb4a3f480c543b58684df734889971964487f09aeb390 Mon Sep 17 00:00:00 2001 From: Wesley van Tilburg Date: Fri, 13 Mar 2026 15:46:13 +0000 Subject: [PATCH] more navigation fixes (primarly disabling mouse when terminal is open) --- lua/core/autocmds.lua | 43 +++++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/lua/core/autocmds.lua b/lua/core/autocmds.lua index d6b16b8..923e9e9 100644 --- a/lua/core/autocmds.lua +++ b/lua/core/autocmds.lua @@ -195,29 +195,30 @@ vim.keymap.set("n", "", function() wrap_move("h") end, { desc = "Move to le vim.keymap.set("n", "", function() wrap_move("l") end, { desc = "Move to right pane (wrap)" }) vim.keymap.set("n", "", function() wrap_move("j") end, { desc = "Move to pane below (wrap)" }) vim.keymap.set("n", "", function() wrap_move("k") end, { desc = "Move to pane above (wrap)" }) --- Alt+h/l in terminal: switch terminal tabs if popup is open, otherwise move panes +-- Alt+h/l in terminal: only switch terminal tabs in popup, no pane navigation vim.keymap.set("t", "", function() if popup_term.win and vim.api.nvim_win_is_valid(popup_term.win) then switch_term((popup_term.current - 2) % #popup_term.bufs + 1) - else - vim.cmd("stopinsert") wrap_move("h") end -end, { desc = "Prev term tab / left pane" }) +end, { desc = "Prev term tab" }) vim.keymap.set("t", "", function() if popup_term.win and vim.api.nvim_win_is_valid(popup_term.win) then switch_term(popup_term.current % #popup_term.bufs + 1) - else - vim.cmd("stopinsert") wrap_move("l") end -end, { desc = "Next term tab / right pane" }) -vim.keymap.set("t", "", function() - if popup_term.win and vim.api.nvim_win_is_valid(popup_term.win) then return end - vim.cmd("stopinsert") wrap_move("j") -end, { desc = "Move to pane below (wrap)" }) -vim.keymap.set("t", "", function() - if popup_term.win and vim.api.nvim_win_is_valid(popup_term.win) then return end - vim.cmd("stopinsert") wrap_move("k") -end, { desc = "Move to pane above (wrap)" }) +end, { desc = "Next term tab" }) +-- Block pane navigation in terminal mode +vim.keymap.set("t", "", "") +vim.keymap.set("t", "", "") + +-- Disable mouse when terminal is focused, restore on leave +vim.api.nvim_create_autocmd("TermEnter", { + group = vim.api.nvim_create_augroup("term_no_mouse", { clear = true }), + callback = function() vim.o.mouse = "" end, +}) +vim.api.nvim_create_autocmd("TermLeave", { + group = vim.api.nvim_create_augroup("term_restore_mouse", { clear = true }), + callback = function() vim.o.mouse = "a" end, +}) -- Terminal copy/paste vim.keymap.set("t", "", function() @@ -227,7 +228,17 @@ vim.keymap.set("t", "", function() end end, { desc = "Paste from clipboard" }) vim.keymap.set("t", "", [[V]], { desc = "Select current line (normal mode)" }) -vim.keymap.set("t", "", [[]], { desc = "Exit to normal mode" }) + +-- Auto-enter insert mode when switching to a terminal window +-- Uses WinEnter only (not BufEnter) so :wq from nested editors (e.g. git commit) works +vim.api.nvim_create_autocmd("WinEnter", { + group = vim.api.nvim_create_augroup("term_auto_insert", { clear = true }), + callback = function() + if vim.bo.buftype == "terminal" and vim.fn.mode() ~= "t" then + vim.cmd.startinsert() + end + end, +}) -- Save/restore layout with :mksession vim.opt.sessionoptions = "buffers,curdir,folds,winpos,winsize,terminal"