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?

3
  • 1
    What if you did something like nnoremap <LeftMouse> <LeftMouse>i ?
    – D. Ben Knoble
    Commented Dec 21, 2019 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
    Commented Dec 21, 2019 at 12:55
  • 1
    It's a known issue.
    – dedowsdi
    Commented Dec 24, 2019 at 0:03

1 Answer 1

9
+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
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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