1

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.

JJD
  • 50,076
  • 60
  • 203
  • 339
  • 1
    Move the cursor to the character and type `ga` (in normal mode) to show some information on this character at the bottom of the screen. – Marth Sep 14 '17 at 10:14
  • It outputs: `< > 160, Hex 00a0, Octal 240`. Looks like it is a [non-breaking space](https://en.wikipedia.org/wiki/Non-breaking_space). – JJD Sep 14 '17 at 10:26
  • 1
    Feel free to transform your comment into a "full" answer so I can grant you the answer flag. – JJD Sep 14 '17 at 10:42

2 Answers2

3

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
Marth
  • 23,920
  • 3
  • 60
  • 72
  • 1
    Related article: [Stripping out a non breaking space character ( )](http://www.markhneedham.com/blog/2013/02/23/ruby-stripping-out-a-non-breaking-space-character-nbsp/). – JJD Sep 14 '17 at 14:27
  • If you find yourself needed the unicode names often you may want to look into [characterize.vim](https://github.com/tpope/vim-characterize) – Peter Rincker Sep 18 '17 at 16:09
1

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.

dash-tom-bang
  • 17,383
  • 5
  • 46
  • 62