5

I'm trying to use NeoVim as a tmux replacement, and have found that no matter what I do, I can't get it to go into insert mode when I click in a pane that has a terminal in it.

Here's the config I'm trying to use, with no luck. Currently the config lets me navigate between panes, and when I enter the pane using the keyboard it switches to insert mode.

But when I enter the pane by clicking the mouse, it goes back to normal mode, which I almost never want.

~/.config/nvim/init.vim

set mouse=a

if has('nvim') autocmd TermOpen term://* startinsert autocmd TermEnter term://* startinsert autocmd BufEnter term://* startinsert endif

" Edit files within Nvim's terminal without nesting sessions. augroup prevent_nested_edit autocmd VimEnter * if !empty($NVIM_LISTEN_ADDRESS) && $NVIM_LISTEN_ADDRESS !=# v:servername \ |let g:r=jobstart(['nc', '-U', $NVIM_LISTEN_ADDRESS],{'rpc':v:true}) \ |let g:f=fnameescape(expand('%:p')) \ |noau bwipe \ |call rpcrequest(g:r, "nvim_command", "edit ".g:f) \ |call rpcrequest(g:r, "nvim_command", "call lib#SetNumberDisplay(1)") \ |qa \ |endif augroup END

NOTE: I have found very similar questions, but they don't seem to work for when I "click" in the terminal - they work for navigating into the terminal pane with the keyboard:

How to enter insert mode when entering neovim terminal pane?

Brad Parks
  • 175
  • 1
  • 13

1 Answers1

9

Neovim's terminal has "a specialty": a mouse click automatically switches it to "Terminal-Normal" mode. (BTW. That's not a case for Vim, so it does not suffer from this issue.)

So it won't work from <LeftMouse>, but we can map <LeftRelease> instead:

if has('nvim')
    augroup terminal_setup | au!
        autocmd TermOpen * nnoremap <buffer><LeftRelease> <LeftRelease>i
        " more stuff
    augroup end
endif
Matt
  • 20,685
  • 1
  • 11
  • 24