Is there a way to show the character under the cursor in the statusline?
I already use %b\ (0x%B)
to display decimal and hexadecimal value of the character. I would like to display the char itself as well before these two.
There's no predefined item (as listed under :help 'statusline'
, but you can implement this with a custom expression (item %{...}
):
let &statusline .= "%{matchstr(getline('.'), '\\%' . col('.') . 'c.')}"
(I'm using :let
instead of :set
to avoid having to escape all spaces; it's more readable this way.)
getline('.')
obtains the current line, and the character under the cursor is retrieved via the special \%c
atom that matches at a certain column; col('.')
is the current column. The .
then matches the character there, and matchstr()
extracts it.