From 6ab41033bfee825cfe92c0e2f795c060c1b900b3 Mon Sep 17 00:00:00 2001 From: rootiest Date: Wed, 18 Dec 2024 14:25:57 -0500 Subject: [PATCH] feat: add autocommands to enter insert mode in terminal buffers --- lua/data/autocmd.lua | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/lua/data/autocmd.lua b/lua/data/autocmd.lua index a834cc0..c6746f8 100644 --- a/lua/data/autocmd.lua +++ b/lua/data/autocmd.lua @@ -90,4 +90,42 @@ M.minifiles = { end, } +-- Create an autogroup for the TermInsertMode autocmds +local TermInsertMode = augroup('TermInsertMode', { clear = true }) + +-- Start terminal in insert mode +autocmd({ 'TermOpen' }, { + group = TermInsertMode, + pattern = { '*' }, + callback = function() + if vim.opt.buftype:get() == 'terminal' then + -- if filetype does not contain 'dashboard' + if not string.find(vim.opt.filetype:get(), 'dashboard') then + -- If window is editable + if vim.opt.modifiable:get() then + vim.cmd(':startinsert') + end + end + end + end, +}) + +-- When entering a terminal buffer auto switch to insert mode +-- I could use TermEnter event but it does not work when switching between window splits +autocmd({ 'BufEnter' }, { + group = TermInsertMode, + pattern = { '*' }, + callback = function() + if vim.opt.buftype:get() == 'terminal' then + -- if filetype does not contain 'dashboard' + if not string.find(vim.opt.filetype:get(), 'dashboard') then + -- If window is editable + if vim.opt.modifiable:get() then + vim.cmd(':startinsert') + end + end + end + end, +}) + return M