# How to get the encoded byte sequence for a character in the status line?

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

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 %{}).

See:

:h redir
:h 'statusline'