Skip to content

Instantly share code, notes, and snippets.

@Velrok
Last active November 20, 2025 22:34
Show Gist options
  • Select an option

  • Save Velrok/b72bddcad697cc6f95afbc941059ac11 to your computer and use it in GitHub Desktop.

Select an option

Save Velrok/b72bddcad697cc6f95afbc941059ac11 to your computer and use it in GitHub Desktop.
-- Automatically enter insert mode when entering a terminal buffer window
vim.api.nvim_create_autocmd({ "BufEnter", "WinEnter" }, {
pattern = "term://*",
callback = function()
vim.cmd("startinsert")
end,
desc = "Enter insert mode when entering terminal buffer window",
})
-- Set up terminal-specific keymaps for window navigation in terminal mode
vim.api.nvim_create_autocmd("TermOpen", {
pattern = "*",
callback = function()
local opts = { noremap = true, silent = true, buffer = true }
-- <C-\\><C-n> will exit terminal (insert) mode
vim.keymap.set("t", "<C-h>", "<C-\\><C-n><C-w>h", vim.tbl_extend("force", opts, { desc = "switch to west pane" }))
vim.keymap.set("t", "<C-j>", "<C-\\><C-n><C-w>j", vim.tbl_extend("force", opts, { desc = "switch to south pane" }))
vim.keymap.set("t", "<C-k>", "<C-\\><C-n><C-w>k", vim.tbl_extend("force", opts, { desc = "switch to north pane" }))
vim.keymap.set("t", "<C-l>", "<C-\\><C-n><C-w>l", vim.tbl_extend("force", opts, { desc = "switch to east pane" }))
end,
desc = "Set up terminal window navigation in terminal mode",
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment