Sunday, December 11, 2011

Re: How to put a character the statusline?

On 12/12/11 05:13, Bee wrote:
> I know how to put the decimal and hex equivalent of the character
> under the cursor in the statusline:
>
> set statusline+=%b " decimal byte '98'
> set statusline+=\x%02B " hex byte 'x62'
>
> How to put the character itself in the statusline?
>
> -Bill
>

maybe (untested)

set stl+=%{substitute(getline('.'),\ '^.*\\(\\%'\ .\ virtcol('.')\ .\
'v.\\).*$',\ '\\1',\ '')}

with two single quotes (not just one double quote, and if you want two
double quotes they must be backslash-escaped) before the last closing
parenthesis.

or (maybe more readable)

let &stl .= '%{substitute(getline("."), ''^.*\(\%'' . virtcol(".") .
''v.\).*$'', ''\1'', "")}'

(here we must beware that to include a single quote in a single-quoted
string we must double it)

see
:help option-backslash
for the backslash-escaping in the operand of :set
:help 'statusline'
for %{ and }
:help expr-'
about the need for doubling ' inside a 'string'
and also
:help substitute()
:help getline()
:help pattern-atoms
:help :let-option

Best regards,
Tony.
--
Q: Where does virgin wool come from?
A: Ugly sheep.

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