1

Suppose ALT+h to mapped to <C-\><C-N><C-w>j as following Nvim documentation: nvim_terminal_emulator. We have two horizontally split windows with terminal buffers and the right window is activated.

After hitting ATL+h, the left window will be activated but the right window will be switched to normal mode automatically. Is it possible to let the right window stay in terminal mode for neovim? Or does neovim has equivalent terminal-typing which allows us to not leave the terminal mode.

1 Answer 1

3

:h <Cmd> pseudokey is answers this problem:

tnoremap <alt-h> <Cmd>wincmd h<CR>
tnoremap <alt-j> <Cmd>wincmd j<CR>
tnoremap <alt-k> <Cmd>wincmd k<CR>
tnoremap <alt-l> <Cmd>wincmd l<CR>

Also see :help <Cmd>.

8
  • Thanks for the answer! But sometimes I don't want to re-enter terminal-insert mode automatically. For example after running a large test suite in neovim's terminal, I need to go back and forth between test output and source code to find out why some tests failed. When switching back to the test output, I want to check the output in the middle of the screen but startinsert will automatically scroll the screen to bottom. The problem for neovim is in order to run a command in terminal-insert mode, we have to leave this terminal-insert mode via <C-\><C-N> first.
    – Coiby
    Jun 1, 2020 at 14:30
  • Considering we can run a command in insert mode without leaving insert mode, for example, <C-r> REGISTER to paste some text from a register, it doesn't make sense we have to leave terminal-insert mode first to run a command.
    – Coiby
    Jun 1, 2020 at 14:39
  • This is reported as a bug tnoremap <Cmd>wincmd doesn't preserve mode · Issue #12246 · neovim/neovim on github. Hopefully it will be fixed soon.
    – Coiby
    Jun 1, 2020 at 15:03
  • @Coiby Note that the issue is about Neovim-specific <cmd>. <c-\><c-n> should and will work the way it does.
    – Matt
    Jun 1, 2020 at 15:16
  • 1
    @ColinKennedy Sorry for the late reply. I eventually switch to vim after implementing github.com/vim/vim/pull/6290
    – Coiby
    Nov 28, 2021 at 3:48

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.