【问题标题】:What is the whitespace character is in my Git commit message?我的 Git 提交消息中的空白字符是什么?
【发布时间】:2018-02-23 06:34:10
【问题描述】:

我的 Git 提交消息包含一个空白字符,当我输出 git log 或运行 gitk 时,它看起来像一个简单的 空格。但是,当我使用 Vim 打开 Git 提交消息时,space 显示为 underbar,如屏幕截图所示。怎样才能知道这是什么字符?如果你能告诉我如何复制它,我会把它粘贴在这里。

屏幕截图显示了 MacOS 上 iTerm 中 Vim 中的 Git 提交消息。

【问题讨论】:

  • 将光标移动到该字符并输入ga(在正常模式下)以在屏幕底部显示有关该字符的一些信息。
  • 它输出:< > 160, Hex 00a0, Octal 240。看起来是non-breaking space
  • 随时将您的评论转换为“完整”答案,以便我可以授予您答案标志。

标签: git vim special-characters whitespace commit-message


【解决方案1】:

使用 vim,您可以使用ga(在正常模式下)将光标放在字符上,以十进制、十六进制和八进制打印其 ascii 值。

来自: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.

例如,将gaa 上的字符一起使用会显示:

<a>  97,  Hex 61,  Octal 141

【讨论】:

【解决方案2】:

如果您发现自己经常想查看字符代码,可以将其放入状态行和/或标尺格式:

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%)

最后的%02B 总是将字符代码放在窗口的右边距(如果你的字符值大于255,它会增加宽度)。我在它前面加上 0x 只是为了记住它是十六进制的。

【讨论】:

    猜你喜欢
    • 2013-03-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-11
    • 2011-09-07
    • 2021-06-18
    • 2021-03-06
    相关资源
    最近更新 更多