From: Samir Benmendil Date: Sat, 14 Jan 2023 01:12:52 +0000 (+0000) Subject: vim: consolidate terminal setings in plugin file X-Git-Url: https://git.rmz.io/dotfiles.git/commitdiff_plain/e139e0723a3a4d11862c128f8f2e1aba729f3848 vim: consolidate terminal setings in plugin file Also supports nvim terminal and make it more like normal vim one. --- diff --git a/vim/plugin/terminal.vim b/vim/plugin/terminal.vim new file mode 100644 index 0000000..f3170d3 --- /dev/null +++ b/vim/plugin/terminal.vim @@ -0,0 +1,53 @@ +" 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 * startinsert + autocmd TermOpen * if &buftype == 'terminal' | setlocal bufhidden=hide | endif + autocmd CmdlineLeave,WinEnter,BufWinEnter * call timer_start(0, function('s:TermEnter'), {}) + endif +augroup END diff --git a/vim/vimrc b/vim/vimrc index 0aee7e3..34afc34 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -418,11 +418,6 @@ augroup END command! NoAutoChecktime let b:autochecktime=0 command! ToggleAutoChecktime let b:autochecktime=!get(b:, 'autochecktime', 0) | echom "b:autochecktime:" b:autochecktime -augroup terminal - au! - au TerminalOpen * if &buftype == 'terminal' | setlocal bufhidden=hide | endif -augroup END - " bindings {{{1 " allow both and \ to be