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?
Vi and Vim Stack Exchange is a question and answer site for people using the vi and Vim families of text editors. It only takes a minute to sign up.
Sign up to join this communityIn 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?
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.
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
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.
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