I tried to remap my split navigation like explained here. Moving to the top or right split works but ther other two just do nothing. I tried the same without a .vimrc which led to the same result. Later i tried the same in GVim where all of them worked so i guessed it has something to do with vim running in the terminal. Then i figured out that pressing in my terminal doesn't act like backspace as it should.
What can i do to fix this?

  • You're on Windows, I assume? Terminal vim on windows gets mapped to <C-h>, however this still shouldn't mess up your mapping so I'm not sure what's going on there. To fix the backspace issue you can do inoremap <C-h> <BS>, but I can't say that I know why <C-j> and <C-h> aren't working. – Tumbler41 Dec 22 '16 at 16:36
  • No i'm on Linux Mint. Just installed terminator and there it works. Seems to be some issue with Gnome Terminal. – Benjamin Zinschitz Dec 22 '16 at 16:45

Your comment indicates that this problem exists only with certain terminal emulators like gnome-terminal

No I'm on Linux Mint. Just installed terminator and there it works. Seems to be some issue with Gnome Terminal

Gnome-terminal is known to have trouble with mapping modifier keys in vim

Example: The problem is that in a terminal, a Tab character is ^I (Control-I). This means that pressing control while pressing tab is not something the terminal even bothers to pass through to Vim. It just sends a regular tab character.

GVim can support this because it doesn't have to rely on the terminal to tell it what keys are being pressed in what combination--it has more direct access to keyboard events, so it has no trouble seeing modified special keys.

While it's possible for X to recognize such combinations, applications that run in a terminal (or, these days, a terminal emulator) cannot. This is because, historically, terminals could only send and receive seven- or eight-bit sequences of ASCII data across a serial connection (though this could include "escape sequences" that position the cursor, scroll or delete lines, change color and other helpful effects).

There are some workarounds for it:

First, we need to know what command your terminal sends when a certain key combination is pressed:

To do so press Control + Shift + v Now press the key combination Ctrl-j and Ctrl-h

Ex: I am running headless server and for me Shift+Enter or Control+Enter or Enter shows the same output ^M but Alt+Enter shows ^[ This means that shift+enter and control+enter and enter are taken similarly by the terminal. So mapping shift+enter combination would also affect enter combinations.

  1. Record your output

enter gives me ^M and \r

  1. man ascii

Look in the manpages of ascii and you will see that \r is for CR so now mapping <CR> will map enter keys

Following these methods you might be able to find the specific char

Even though it should solve the problem, YMMV

Some people (foremost Paul LeoNerd Evans) want to fix that (even for console Vim in terminals that support this), and have floated various proposals..

Vim's keyboard input system revolves centrally around a queue of bytes. This worked well when all the world was serial terminals. In this new world of GUIs this model doesn't work so well. I advocate changing it to a queue of keypress events.

| improve this answer | |
  • Thank you for all that information. I did what you suggested and noticed that there is no output for Ctrl - g Ctrl - h and Ctrl - j while Ctrl - f opened a search window. So i looked at Gnome Terminals Shortcuts and found that these four combinations were mapped to find actions. Unmapping them solved my problem! – Benjamin Zinschitz Jan 2 '17 at 13:19
  • Ah ! Glad your problem is solved. I had a doubt that those keys were already mapped. Happy to help ! – Ashok Arora Jan 2 '17 at 13:44

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