3

I rebound control + H/J/K/L to navigate between splits without needing <C-W>:

nnoremap <C-J> <C-W><C-J>
nnoremap <C-K> <C-W><C-K>
nnoremap <C-L> <C-W><C-L>
nnoremap <C-H> <C-W><C-H>

However, when inside a terminal opened with :terminal, these keybinds are interpreted as terminal commands. <C-L> clears the terminal instead of moving to the right, for example. Is it possible to use my same navigation commands inside the vim terminal?

I'm running bash in Terminal.app on Mac OS X, if that's relevant.

  • Nice, that worked! If you'd like, you can write it up as an answer and I'll accept it :-) – Adam Hammes Sep 4 at 15:58
  • Sure! Glad that solved the problem for you. Will turn it into an answer. – filbranden Sep 4 at 16:12
4

You need to use :tnoremap to map keys in the :terminal window.

So if you want that to work in both normal mode of a regular buffer and of terminal windows, you need to add another set of mappings for the terminal:

tnoremap <C-J> <C-W><C-J>
tnoremap <C-K> <C-W><C-K>
tnoremap <C-L> <C-W><C-L>
tnoremap <C-H> <C-W><C-H>

Beware that these keys usually have useful functions in programs running inside the terminal window (such as the shell.) For example, <C-h> to backspace last character, <C-l> to redraw the screen, <C-k> to delete from cursor to end of line. You should think twice about whether you're going to miss any of them. If you want to preserve them, you can also adding alternative mappings (possibly longer ones) mapping back to the keys you're remapping here.

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.