more navigation fixes (primarly disabling mouse when terminal is open)

This commit is contained in:
Wesley van Tilburg
2026-03-13 15:46:13 +00:00
parent 981cd0d732
commit 19b489e531

View File

@@ -195,29 +195,30 @@ vim.keymap.set("n", "<A-h>", function() wrap_move("h") end, { desc = "Move to le
vim.keymap.set("n", "<A-l>", function() wrap_move("l") end, { desc = "Move to right pane (wrap)" }) vim.keymap.set("n", "<A-l>", function() wrap_move("l") end, { desc = "Move to right pane (wrap)" })
vim.keymap.set("n", "<A-j>", function() wrap_move("j") end, { desc = "Move to pane below (wrap)" }) vim.keymap.set("n", "<A-j>", function() wrap_move("j") end, { desc = "Move to pane below (wrap)" })
vim.keymap.set("n", "<A-k>", function() wrap_move("k") end, { desc = "Move to pane above (wrap)" }) vim.keymap.set("n", "<A-k>", 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", "<A-h>", function() vim.keymap.set("t", "<A-h>", function()
if popup_term.win and vim.api.nvim_win_is_valid(popup_term.win) then 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) switch_term((popup_term.current - 2) % #popup_term.bufs + 1)
else
vim.cmd("stopinsert") wrap_move("h")
end end
end, { desc = "Prev term tab / left pane" }) end, { desc = "Prev term tab" })
vim.keymap.set("t", "<A-l>", function() vim.keymap.set("t", "<A-l>", function()
if popup_term.win and vim.api.nvim_win_is_valid(popup_term.win) then if popup_term.win and vim.api.nvim_win_is_valid(popup_term.win) then
switch_term(popup_term.current % #popup_term.bufs + 1) switch_term(popup_term.current % #popup_term.bufs + 1)
else
vim.cmd("stopinsert") wrap_move("l")
end end
end, { desc = "Next term tab / right pane" }) end, { desc = "Next term tab" })
vim.keymap.set("t", "<A-j>", function() -- Block pane navigation in terminal mode
if popup_term.win and vim.api.nvim_win_is_valid(popup_term.win) then return end vim.keymap.set("t", "<A-j>", "<Nop>")
vim.cmd("stopinsert") wrap_move("j") vim.keymap.set("t", "<A-k>", "<Nop>")
end, { desc = "Move to pane below (wrap)" })
vim.keymap.set("t", "<A-k>", function() -- Disable mouse when terminal is focused, restore on leave
if popup_term.win and vim.api.nvim_win_is_valid(popup_term.win) then return end vim.api.nvim_create_autocmd("TermEnter", {
vim.cmd("stopinsert") wrap_move("k") group = vim.api.nvim_create_augroup("term_no_mouse", { clear = true }),
end, { desc = "Move to pane above (wrap)" }) 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 -- Terminal copy/paste
vim.keymap.set("t", "<C-v>", function() vim.keymap.set("t", "<C-v>", function()
@@ -227,7 +228,17 @@ vim.keymap.set("t", "<C-v>", function()
end end
end, { desc = "Paste from clipboard" }) end, { desc = "Paste from clipboard" })
vim.keymap.set("t", "<C-y>", [[<C-\><C-n>V]], { desc = "Select current line (normal mode)" }) vim.keymap.set("t", "<C-y>", [[<C-\><C-n>V]], { desc = "Select current line (normal mode)" })
vim.keymap.set("t", "<Esc>", [[<C-\><C-n>]], { 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 -- Save/restore layout with :mksession
vim.opt.sessionoptions = "buffers,curdir,folds,winpos,winsize,terminal" vim.opt.sessionoptions = "buffers,curdir,folds,winpos,winsize,terminal"