Monday, October 25, 2010

Re: Statusline with %b, %B and %O matching ga

On Mon, 25 Oct 2010, Fernando Basso wrote:

> I'd like the statusline to match the result of when we hit ga while
> the cursor is on a char.
>
> For example, if the cursor is over 'a', ga gives me:
> <a> 97, Hex 61, Octal 141
>
> However statusline with Dec=%b\ Hex=%B\ Oct=%O gives me
> Dec=97 Hex=61 Oct=1
>
> So, I would like to have the 'Oct' (in my statusline) to be the same
> 'Octal' value we get when hitting 'ga'.

That's not what '%O' gives you, as you noticed ('O' is for 'O'ffset;
when capitalized, it's in hexadecimal.)

Instead of %O, you could use:

%{printf("Oct=%03o", char2nr(strpart(getline("."), col(".") - 1, 1)))}

[No spaces, if you don't want to escape them, otherwise, needs
backslashes]:
%{printf("Oct=%03o",char2nr(strpart(getline("."),col(".")-1,1)))}

(tested, but the behavior on empty lines could be improved)

Best,
Ben

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments: