]> git.frustrated-labs.net Git - dotfiles.git/commitdiff
nvim: add keymaps for toggleterm
authorAlexander Goussas <[email protected]>
Thu, 12 Jun 2025 02:28:40 +0000 (21:28 -0500)
committerAlexander Goussas <[email protected]>
Thu, 12 Jun 2025 02:28:40 +0000 (21:28 -0500)
These are for being able to navigate between panes when the terminal buffer is active.

nvim/.config/nvim/init.lua

index 30abddc6310669fc5b9b6118d09cab250bba5133..b1e72c1528af5502520885aa14411c72e3d5a8e4 100644 (file)
@@ -234,11 +234,27 @@ require("lazy").setup({
           command = "tno <silent><leader>tt <Cmd>ToggleTerm<CR>"
         })
 
+        function _G.set_terminal_keymaps()
+          local opts = {buffer = 0}
+          vim.keymap.set('t', '<esc>', [[<C-\><C-n>]], opts)
+          vim.keymap.set('t', 'jk', [[<C-\><C-n>]], opts)
+          vim.keymap.set('t', '<C-h>', [[<Cmd>wincmd h<CR>]], opts)
+          vim.keymap.set('t', '<C-j>', [[<Cmd>wincmd j<CR>]], opts)
+          vim.keymap.set('t', '<C-k>', [[<Cmd>wincmd k<CR>]], opts)
+          vim.keymap.set('t', '<C-l>', [[<Cmd>wincmd l<CR>]], opts)
+          vim.keymap.set('t', '<C-w>', [[<C-\><C-n><C-w>]], opts)
+        end
+
+        vim.api.nvim_create_autocmd({"TermEnter"}, {
+          pattern = "term://*toggleterm#*",
+          command = "lua set_terminal_keymaps()"
+        })
+
         require("toggleterm").setup({
           shade_terminals = false,
         })
       end
-    }
-  ,
+    },
+  }
 })