" adapted from https://www.reddit.com/r/vim/comments/op677w/making_neovim_terminal_behave_like_vim_terminal/h642b6b/ function! s:TermEnter(_) if getbufvar(bufnr(), 'term_insert', 0) startinsert call setbufvar(bufnr(), 'term_insert', 0) endif endfunction function! TermExec(cmd) let b:term_insert = 1 execute a:cmd endfunction if !has('nvim') command! -nargs=* T terminal command! -nargs=* VT vertical terminal else command! -nargs=* T split | terminal command! -nargs=* VT vsplit | terminal tnoremap . tnoremap tnoremap \ tnoremap tnoremap N tnoremap :call TermExec('call feedkeys(":")') tnoremap call TermExec('wincmd w') tnoremap W call TermExec('wincmd W') tnoremap call TermExec('wincmd w') tnoremap call TermExec('wincmd W') tnoremap h call TermExec('wincmd h') tnoremap j call TermExec('wincmd j') tnoremap k call TermExec('wincmd k') tnoremap l call TermExec('wincmd l') tnoremap call TermExec('wincmd h') tnoremap call TermExec('wincmd j') tnoremap call TermExec('wincmd k') tnoremap call TermExec('wincmd l') tnoremap gt call TermExec('tabn') tnoremap gT call TermExec('tabp') endif augroup terminal au! if !has('nvim') autocmd TerminalOpen * if &buftype == 'terminal' | setlocal bufhidden=hide | endif else autocmd TermOpen * lua if vim.startswith(vim.api.nvim_buf_get_name(0), "term://") then vim.cmd("startinsert") end autocmd TermOpen * if &buftype == 'terminal' | setlocal bufhidden=hide | endif autocmd CmdlineLeave,WinEnter,BufWinEnter * call timer_start(0, function('s:TermEnter'), {}) endif augroup END