2

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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