3

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?

| improve this question | | | | |
  • 1
    What if you did something like nnoremap <LeftMouse> <LeftMouse>i ? – D. Ben Knoble Dec 21 '19 at 2:49
  • 1
    @Ben Knoble - tried various flavors of that, and none of them worked - just tried that one too, and still a no go – Brad Parks Dec 21 '19 at 12:55
  • 1
    It's a known issue. – dedowsdi Dec 24 '19 at 0:03
4
+50

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
| improve this answer | | | | |
  • awesome! thanks @Matt ! that totally worked! – Brad Parks Dec 24 '19 at 14:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.