I want to display the hex byte sequence for the character under the cursor as it is actually stored on disk.

Currently my status line contains 0x%04.5B which works fine for ASCII/latin1 files but for UTF-8 it only gives me the Unicode code point which is not what is actually stored on disk.

For example, for the German letter Ä it shows 0x00C4 which corresponds to Unicode character U+00C4. But the actual UTF-8 encoding is c3 84.

I also know about ga and g8 but I don't know how to use their output in the status line.

What I want to achieve:

  • For utf-8 files show the output of g8 in the status line
  • For latin1 files show the Hex ... part of ga in the status line

1 Answer 1


In addition to @D. Ben Knoble’s suggestion, you can capture the result of a normal mode command (g8 in this example) using :redir to store it in a variable:

redir => char_bytes
exec 'normal! g8'
redir END

Then you can add it to your status line however you see fit (probably with the item %{}).


:h redir
:h 'statusline'
  • Watch out for those curly quotes :)
    – D. Ben Knoble
    Aug 29, 2020 at 13:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.