ASCII Characters as They Appear in Vim and in the Windows Command Prompt

Each character in a file is, ultimately, just a byte-value between zero and 255. However, this consistency still makes for some unexpected effects when viewing the same file in different software (and fonts), and on different systems.

This can cause confusion when handling text generated on the command line and then viewed in Vim (or any text editor, for that matter), presumably after redirecting the text into a file.

The following screenshots show the values 0 to 255 (with a few exceptions to keep things readable) in Vim and in the Windows Command Prompt. The font was Consolas in both cases, but the size was different; 23pt in Vim and 36pt in the Command Prompt (which, strangely enough, resulted in the same physical size on the screen).

The missing characters were all control characters, and were as follows:

All control characters (below 32, on rows 0 and 1) have a symbol associated with them, except for 0 (Ctrl-@, NULL), at least in the old DOS IBM character set. However, these symbols do not appear in Vim (instead, it shows digraphs indicating the corresponding Ctrl letter), and not all appear in the Command Prompt. The ones that do appear in the Command Prompt are 1 to 6, 11, 12, 14, and 15.

Apart from the way that Vim shows the control characters, there is a fundamental difference in the appearance of the extended characters (128 and above, on rows 8 to F), even though they are viewed in the same font.

ASCII Characters in the Command Prompt

ASCII Characters in Vim

These outputs were generated with the following VBScript program.

' Some of the control characters show up better as one-per-line.
For y = 0 To 15
    WScript.Echo y & "=" & Chr(y)
Next ' y

z = 0
strHeading = "  "
For x = 0 To 15
    strASCII = Hex(x) & " "
    For y = 0 To 15
        If x = 0 Then strHeading = strHeading & "  " & Hex( y )
        strASCII = strASCII & "  "
        ' Use the following IF for command-prompt output.
        ' For some reason, including Chr(0) prevents the rest of the line
        ' displaying. The other characters (7, 8, 9, 10, and 13) don't show up
        ' or spoil the layout.
        'If (z > 0 And z < 7) Or (z > 10 And z < 13) Or (z > 13) Then
        ' Use the following IF for output read into Vim.
        ' Vim doesn't like zero (first line doesn't show), and Chr(10) drops a
        ' line. Note that Chr(8), which is Tab, shows as a tab normally would
        ' (unless you use :set list, in which case it appears as "^I").
        If (z > 0 And z < 10) Or (z > 10) Then
            strASCII = strASCII & Chr(z)
            strASCII = strASCII & " "
        End If
        z = z + 1
    Next ' y
    If x = 0 Then WScript.Echo strHeading
    WScript.Echo strASCII
Next ' x

Home About Me
Copyright © Neil Carter

Content last updated: 2011-07-19