2

In normal mode, I tried CTRL-H and CTRL-L, and I found that the former worked while the latter didn't do anything at all.

I wonder why their behaviors are not the same?

2

In normal mode Ctrl-H is same as h -- that is 'move to the left' while Ctrl-L means 'clear and redraw the screen', not 'move to the right'. This Ctrl-L behavior is very similar to bash shell. This is useful for example when you have background process printing some stuff while you are using vim in terminal.

| improve this answer | |
  • I thought ctrl h was the same as backspace (which happens to work like h)? – D. Ben Knoble Aug 5 '18 at 1:03
  • @Ben what you said probably correct. But we use X to delete to the left in normal mode, which is a reverse of x. I don't know why vim/vi author not (also) assign Ctrl-H for this purpose. – tivn Aug 5 '18 at 13:21
  • 1
    Because the backspace key sends an escape sequence, like many other keys, which happens to be ctrl h. And it made sense for backspace to move left a character (space moves right one). So it was the choice of backspace functionality that affected ctrl h. – D. Ben Knoble Aug 5 '18 at 13:23
  • @Ben perhaps you can put your opinion as separate answer so it can benefit everone else. – tivn Aug 5 '18 at 13:34
0

In fact Ctrl-h is ASCII 0x08. If you look this up in a ASCII table, it is defined as "backspace". The Backspace is ASCII 0x7f (127dec). In ASCII this is defined as "DEL". In UNIX-like environments both keys delete the character to the left of the cursor.

In Vim insert mode, both keys delete the character to the left of the cursor. In normal mode both keys just move the cursor to the left (without deleting).

I don't know how Ctrl-h was handled in normal mode of the original Vi, but i think that h and Ctrl-h leads to the same cursor movement is just a coincident.

References:

BTW: What code the key Backspace actually sends might be defined by the terminal. In GNOME-Terminal it can be defined to send Ctrl-H, "ASCII DEL", "Escape Sequence" or "TTY Erase". AFAIK "ASCII DEL" is the default.

| improve this answer | |
  • On FreeBSD, which I believe uses nvi, Ctrl-H and Backspace are one and the same. For example, creating a mapping for Ctrl-H (via pressing Ctrl-V Ctrl-H) and pressing Backspace will fire that mapping. This is not the case in Vim, as it can differentiate between the two. – ZeroKnight Jan 3 '19 at 12:02
  • @ZeroKnight This might also be due to terminal settings. See my update. – Ralf Jan 3 '19 at 12:41

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.