Thursday, November 24, 2011

Re: Character count in current paragraph

On 24/11/11 5:32 PM, Christian Brabandt wrote:
> On Thu, November 24, 2011 5:56 am, Ben Schmidt wrote:
>> Hi, guys!
>>
>> Looking for some Vim voodoo a little bit outside my areas of expertise!
>>
>> I'd like to put the number of characters in the current paragraph (i.e.
>> area
>> between empty lines) in my ruler, or have it displayed when I press a key
>> (either
>> will do). That will save me having to exit normal mode and do vipg<C-g>
>> and then
>> scan the status line for the relevant count every time I'm interested in
>> it. I'm
>> editing 7-bit text, so number of bytes would be just as good.
>>
>> I'm in a bit of a hurry and would just love it if one of you could chuck
>> me an
>> answer that I can copy and paste!
>
> I think either of those two will work:
> :'{,'}s/./&/gn
> or even:
> :echo eval(join(map(getline("'{", "'}"),
> \ 'len(split(v:val, ''\zs''))'), '+'))
>
> Those two won't include the line-ending bytes when counting (as g<C-G>
> does. If you need this, you can possibly also map something using the
> line2byte() function:
> :echo line2byte(line("'}")) - line2byte(line("'{")+1)

Thanks, Christian.

I'm using the last one, as I like the linebreaks counted (at least for
now) as they will be turned into spaces when the lines are joined (which
is what will happen before they are pasted into a textbox with a
character limit!). I'm sure the second last one could easily squeeze in
a +1 to count the linebreaks, too, though.

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:

Post a Comment