0

I like the terminal in neovim. I am accustomed to tmux and tmux's copy-mode, and type q to exit copy-mode to return back to regular-interactive-mode. Now, in neovim, when in NORMAL mode (which is akin to copy-mode in tmux), I end up typing q hoping to get back to INSERT mode, only to realize nothing happening (as neovim dutifully prepares to start recording). I also use macro recording in vim.

So, is there a way to normal-mode-map q to a only when its a terminal-buffer? And retain q for its existing record-macro use in other buffers?

1

I imagine you can use a buffer-local mapping.

nnoremap <buffer> q a

All you need now is a way to apply it to only terminal buffers. Put the following in your vimrc file:

augroup MyTermMappings
  autocmd!
  autocmd TermOpen * nnoremap <buffer> q a
augroup END

Note: I do not use NeoVim so this is all guesswork.

  • I am using Neovim and verified that the above works. However, anyone who can answer why tnoremap does not work? – Sunny Pun Nov 30 '17 at 17:14
  • 3
    According to :h terminal-input, tmap's only affect terminal-mode which is when keys are pass to the underlying terminal. Think of terminal mode as a variant insert-mode for terminal buffers. – Peter Rincker Nov 30 '17 at 17:19
  • Thanks Peter! How did you find the help tag that describes this behaviour? (By the way, I am on Nvim 0.2.0 and the tag is :h terminal-emulator-input, for whoever interested to read that part of the manual) – Sunny Pun Nov 30 '17 at 17:31
  • 3
    I only have access to NeoVim's online docs. You should of course use your local help files. I found the doc by searching for equivalent of :h :term which lead me to :h terminal where I read the terminal_emulator.txt help page. Which has the information you are looking for and the tag. However if I had neovim I would probably do :h term<c-d> to list out terminal topics or searched via :helpgrep terminal. How to use :help – Peter Rincker Dec 1 '17 at 15:45
1

I can't comment, only post an answer, but I'd like to say that the

augroup MyTermMappings
  autocmd!
  autocmd TermOpen * nnoremap <buffer> q a
augroup END

works but it must go in your init.vim file and not your standard .vimrc if you use vi/m at all. Putting it into the .vimrc file causes a No such group or event: TermOpen * nnoremap <buffer> ... error.

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.