Skip to content

Commit

Permalink
vim: Improve conditions for automatic insert mode on TermOpen
Browse files Browse the repository at this point in the history
When a terminal buffer is opened (TermOpen), for example, by `:term`,
we would want to automatically enter the insert mode. However,
the existing autocmd may result in the non-terminal buffer unwantedly
entering the insert mode when a new terminal buffer is opened on a
floating window. To prevent this, we can enter the insert mode
only if the current window has the terminal buffer being opened.

See nvim-neotest/neotest#2 for reference.
  • Loading branch information
wookayin committed Jun 8, 2022
1 parent 9cf79dc commit 6771ae9
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion vim/vimrc
Expand Up @@ -431,7 +431,7 @@ if has('nvim')
augroup terminal_autoinsert
autocmd!
autocmd BufWinEnter,WinEnter * if &buftype == 'terminal' | startinsert | endif
autocmd TermOpen * startinsert
autocmd TermOpen * if nvim_buf_get_name(0) =~# '^term://' | startinsert | endif

" mouse click puts into normal mode even in terminal; disable this
autocmd TermOpen * tnoremap <buffer><silent> <LeftRelease> <Nop>
Expand Down

0 comments on commit 6771ae9

Please sign in to comment.