Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Caret notation and control characters in Vim

Tags:

terminal

vim

In Vim (or in a terminal?), control characters and their caret notation cannot be distinguished, like Enter vs. C-M. However, there is an only exception; BS vs. C-H.
Why are they only privileged?

For example, if you map Enter to NOP, also C-M will be mapped. Other many control characters have the same behavior. On the other hand, BS and C-H can be mapped to different keys respectively.

:map <Enter> <NOP> // also <C-M> will be mapped
:map <BS> <NOP>    // only <BS> will be mapped, <C-H> won't
like image 948
A01 Avatar asked Feb 27 '26 15:02

A01


1 Answers

You can insert a backspace into a file by pressing controlV before the backspace. In that case, vim (and most editors) will display it as ^H. But normally backspace is treated as a command (telling vim to do something, depending on the mode).

When moving the cursor in a file containing control characters, you can readily distinguish between a control character versus caret next to another character: as you move the cursor left/right, vim will move two columns for the control character, but one column for each of the caret and other character.

like image 69
Thomas Dickey Avatar answered Mar 02 '26 07:03

Thomas Dickey



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!