How do I write control characters in a file using Vim? For example, I want to write the backspace character, which is invoked using ^? (or the dedicated Backspace) key on the keyboard, to a file. But I can't seem to do that - everything I try just erases a character.
The Unix Programming Environment by Kernighan and Pike says (§2.1 The basics of files):
It is important in each case to distinguish between how the character is stored in a file and how it is interpreted in various situations. For example, when you type a backspace on your keyboard (and assuming that your erase character is backspace), the kernel interprets it to mean that you want to discard whatever character you typed previously. Both that character and the backspace disappear, but the backspace is echoed to your terminal, where it makes the cursor move one position backwards.
If you type the sequence
\followed by a backspace), however, the kernel interprets that to mean that you want a literal backspace in your input, so the
\is discarded and the byte
010winds up in your file. When the backspace is echoed on your terminal, it moves the cursor to sit on top of the
When you print a file that contains a backspace, the backspace is passed uninterpreted to your terminal, which again will move the cursor one position backwards. When you use
odto display a file that contains a backspace, it appears as a byte with value
010, or, with the
Basically, it's saying that writing a backslash before backspace character should work (at least for ed). However I'm not able to write it using Vim. How can I write uncommon control characters into the file (such as backspace)