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

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Fernando Basso
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'.

Any help would be appreciated. Thanks in advance.

--
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
Reply | Threaded
Open this post in threaded view
|

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

Benjamin R. Haskell-8
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
Reply | Threaded
Open this post in threaded view
|

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

Christian Brabandt
Hi Benjamin!

On Mo, 25 Okt 2010, Benjamin R. Haskell wrote:

> %{printf("Oct=%03o",char2nr(strpart(getline("."),col(".")-1,1)))}
>
> (tested, but the behavior on empty lines could be improved)

If I am not mistaken, this fails on multibyte chars.

regards,
Christian

--
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
Reply | Threaded
Open this post in threaded view
|

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

Benjamin R. Haskell-8
On Mon, 25 Oct 2010, Christian Brabandt wrote:

> Hi Benjamin!
>
> On Mo, 25 Okt 2010, Benjamin R. Haskell wrote:
>
>> %{printf("Oct=%03o",char2nr(strpart(getline("."),col(".")-1,1)))}
>>
>> (tested, but the behavior on empty lines could be improved)
>
> If I am not mistaken, this fails on multibyte chars.
>

As usual, you're not. :-)

Improved to handle multibyte chars:

%{printf("Oct=%03o",char2nr(get(split(strpart(getline("."),col(".")-1),"\\zs"),0,"")))}

(The 'get()' might be a bit inelegant, but it prevents errors on empty
lines.)

--
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
Reply | Threaded
Open this post in threaded view
|

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

Nikolay Aleksandrovich Pavlov
Reply to message «Re: Statusline with %b, %B and %O matching ga»,
sent 00:24:59 26 October 2010, Tuesday
by Benjamin R. Haskell:

> Improved to handle multibyte chars:
>
> %{printf("Oct=%03o",char2nr(get(split(strpart(getline("."),col(".")-1),"\\z
> s"),0,"")))}
>
> (The 'get()' might be a bit inelegant, but it prevents errors on empty
> lines.)
You are doing something strange: it should be `matchstr' here:
    %{printf("Oct=%03o", char2nr(matchstr(getline("."), '.', col(".")-1))}
This does not invoke lots of ineffective computations.

signature.asc (205 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

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

Fernando Basso
Thank you guys a lot. I didn't have time today to read the help about
the functions
used in the examples you have supplied.

I'm running vim 7.3 on Arch Linux.

I'm currently using this line:
:set statusline=%f\ Buffer=%n\ %m\ %h\ %r\ %=Filetype=%y\ Dec=%b\ Hex=
%B\ %{printf("Oct=%03o",
char2nr(matchstr(getline("."),'.',col(".")-1)))}\ Line=%l\ Col=%c\ %P

It is giving the the message:
E540: Unclosed expression sequence: statusline=%f\ Buffer=%n\ %m\ %h\
%r\ %=Filetype=%y\ Dec=%b\ Hex=%B\ %{printf(

:help E540 was not enough for me to understand what is wrong. I think
I'm using that printf line wrongly.

--
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
Reply | Threaded
Open this post in threaded view
|

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

Florian Rehnisch
On Mon, Oct 25, 2010 at 06:02:46PM -0700, Fernando Basso wrote:

> I'm currently using this line:
> :set statusline=%f\ Buffer=%n\ %m\ %h\ %r\ %=Filetype=%y\ Dec=%b\ Hex=
> %B\ %{printf("Oct=%03o",
> char2nr(matchstr(getline("."),'.',col(".")-1)))}\ Line=%l\ Col=%c\ %P
>
> It is giving the the message:
> E540: Unclosed expression sequence: statusline=%f\ Buffer=%n\ %m\ %h\
> %r\ %=Filetype=%y\ Dec=%b\ Hex=%B\ %{printf(
>
> :help E540 was not enough for me to understand what is wrong. I think
> I'm using that printf line wrongly.

Hmm, ran into the same.  What about sth like this:

:func MyOct()
:  return printf("Oct=%03o",char2nr(matchstr(getline("."),'.',col(".")-1)))
:endfunc

:set statusline=%f\ Buffer=%n\ %m\ %h\ %r\ %=Filetype=%y\ Dec=%b\ Hex=%B\ %{MyOct()}\ Line=%l\ Col=%c\ %P

 flori

--
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
Reply | Threaded
Open this post in threaded view
|

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

Nikolay Aleksandrovich Pavlov
In reply to this post by Fernando Basso
Reply to message «Re: Statusline with %b, %B and %O matching ga»,
sent 05:02:46 26 October 2010, Tuesday
by Fernando Basso:

> It is giving the the message:
> E540: Unclosed expression sequence: statusline=%f\ Buffer=%n\ %m\ %h\
> %r\ %=Filetype=%y\ Dec=%b\ Hex=%B\ %{printf(
>
> :help E540 was not enough for me to understand what is wrong. I think
>
> I'm using that printf line wrongly.
You probably forgot to escape some space or something like that. I cannot debug
this with your autowrap, but try to replace `set' with `let':
    let &statusline="%f Buffer=%n %m %h %r %=Filetype=%y ".
                   \"Dec=%b Hex=%B %{printf('Oct=%03o', ".
                   \"char2nr(matchstr(getline('.'), '.', col('.')-1)))} ".
                   \"Line=%l Col=%c %P"
I tested this and it works.

signature.asc (205 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

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

Jürgen Krämer-4
In reply to this post by Fernando Basso

Hi,

Fernando Basso schrieb:
> Thank you guys a lot. I didn't have time today to read the help about
> the functions
> used in the examples you have supplied.
>
> I'm running vim 7.3 on Arch Linux.
>
> I'm currently using this line:
> :set statusline=%f\ Buffer=%n\ %m\ %h\ %r\ %=Filetype=%y\ Dec=%b\ Hex=%B\ %{printf("Oct=%03o",char2nr(matchstr(getline("."),'.',col(".")-1)))}\ Line=%l\ Col=%c\ %P

either escape the double quotes with backslashes or use single quotes
instead. When not escaped, double quotes start a comment and the rest
of the line is ignored.

Regards,
Jürgen

--
Sometimes I think the surest sign that intelligent life exists elsewhere
in the universe is that none of it has tried to contact us.     (Calvin)

--
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
Reply | Threaded
Open this post in threaded view
|

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

Fernando Basso
In reply to this post by Florian Rehnisch
Either escaping or making a function out of it works fine. Sorry for
my
noobness in the subject. I assure you that I am learning.

Thanks a lot all of you and vim the The Best.

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