What is the whitespace character is in my Git commit message?

916 views Asked by At

My Git commit message contains a whitespace character which looks like a simple space when I output git log or run gitk. However, when I open the Git commit message with Vim the space is displayed as an underbar as shown in the screenshot. How can find out what character this is? I would paste it here if you can tell me how I can copy it.

Git commit message in Vim

The screenshot shows the Git commit message in Vim in iTerm on MacOS.

2

There are 2 answers

2
Marth On BEST ANSWER

Using vim, you can use ga (in normal mode) with the cursor on the character to print its ascii value in decimal, hexadecimal and octal.

From :help ga:

:as[cii]    or                  *ga* *:as* *:ascii*
ga          Print the ascii value of the character under the
            cursor in decimal, hexadecimal and octal.  For
            example, when the cursor is on a 'R':
                <R>  82,  Hex 52,  Octal 122 ~
            When the character is a non-standard ASCII character,
            but printable according to the 'isprint' option, the
            non-printable version is also given.  When the
            character is larger than 127, the <M-x> form is also
            printed.  For example:
                <~A>  <M-^A>  129,  Hex 81,  Octal 201 ~
                <p>  <|~>  <M-~>  254,  Hex fe,  Octal 376 ~
            (where <p> is a special character)
            The <Nul> character in a file is stored internally as
            <NL>, but it will be shown as:
                <^@>  0,  Hex 00,  Octal 000 ~
            If the character has composing characters these are
            also shown.  The value of 'maxcombine' doesn't matter.
            Mnemonic: Get ASCII value.

For instance, using ga with the character on an a shows:

<a>  97,  Hex 61,  Octal 141
0
dash-tom-bang On

If you find yourself regularly wanting to see the character code, you can put it into the statusline and/or rulerformat:

set laststatus=1
set statusline=%F\ %(%w%h%r%m%)%=%2v:%4l/%4L\ 0x%02B
set rulerformat=%25(%w%h%r%<%m%=%2v:%4l/%4L\ 0x%02B%)

The %02B toward the end always puts the character code up against the window's right margin (and it'll grow in width if your character value is greater than 255). I prefix it with 0x just so I remember it's hexadecimal.