]> git.rmz.io Git - dotfiles.git/commitdiff
nvim: only switch terminal to insert mode if it is focused
authorSamir Benmendil <me@rmz.io>
Wed, 17 Jan 2024 23:09:49 +0000 (23:09 +0000)
committerSamir Benmendil <me@rmz.io>
Wed, 21 Feb 2024 01:26:30 +0000 (01:26 +0000)
A terminal may be opened in a floating window, but the insert command
would be applied to the current window.

This was an issue with neotest and nvim-dap, where in some instance it
would switch to insert mode.

See https://github.com/nvim-neotest/neotest/issues/2#issuecomment-1149532666

vim/plugin/terminal.vim

index f3170d378c596f989cd24201c66d55ea0e9d426d..fbed5e61f279efec055bfe2f9333ae9f63ff6bf8 100644 (file)
@@ -46,7 +46,7 @@ augroup terminal
   if !has('nvim')
     autocmd TerminalOpen * if &buftype == 'terminal' | setlocal bufhidden=hide | endif
   else
   if !has('nvim')
     autocmd TerminalOpen * if &buftype == 'terminal' | setlocal bufhidden=hide | endif
   else
-    autocmd TermOpen * startinsert
+    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
     autocmd TermOpen * if &buftype == 'terminal' | setlocal bufhidden=hide | endif
     autocmd CmdlineLeave,WinEnter,BufWinEnter * call timer_start(0, function('s:TermEnter'), {})
   endif