I like to write tutorials and articles for a programming forum I frequent. This forum has a character limit per post. I've used Notepad++ in the past to write posts and it keeps a live character count in the status bar. I'm starting to use gVim more and I really don't want to go back to Notepad++ at this point, but it is very useful to have this character count. If I go over the count, I usually end up pasting the post into Notepad++ so I can see when I've trimmed enough to get by the limit.

I've seen suggestions that :set ruler would help, but this only gives the character count via the current column index on the current line. This would be great if I didn't use paragraph breaks, but I'm sure you'd agree that reading several thousand characters in one paragraph is not comfortable.

I read the help and thought that rulerformat would work, but after looking over the statusline format it uses I didn't see anything that gives a character count for the current buffer.

I've seen that there are plugins that add this, but I'm still dipping my toes into gVim and I'm not sure I want to load random plugins before I understand what they do. I'd prefer to use something built in to vim, but if it doesn't exist it doesn't exist.

What should I do to accomplish my goal? If it involves a plugin, do you use it and how well does it work?

(which then reports back the number of matched chars) or that you do a fancy strlen() on the visually selected text:

:echo strlen(@")

(" is the unnamed register)

since you can call an expression in your statusline like %{myfunc()} that might be a good starting point. counting all the time could be a bit time consuming since you would have to select the whole text and then yank it, but maybe showing the number of bytes in the "-register is ok for you already. if you really want to know the number of chars in the buffer: just visually select ALL the text in the buffer and yank it. so, the solution would be:

:set statusline=%{strlen(@")}

which gives you the number of chars in the "-register (which is identical to the number of bytes if you select and yank the current buffer).

o N Byte number in file of byte under cursor, first byte is 1.
Mnemonic: Offset from start of file (with one added)

which is also a good workaround for your problem. just go to the end of the buffer with G and the byte number shown in your statusline is the number of chars (not true with multi-byte chars of course). go back to where you came from with ctrlo.

When I try this, gVim complains about an unclosed expression sequence. I noticed you are missing a parenthesis, but fixing that doesn't help either. Here's what I rewrote it to: :set statusline=%{ line2byte(line("$")) }
–
OwenPJun 7 '10 at 17:51

Probably you want ...%{ line2byte(line(\"$\")+1))-1 } so that it includes the last line's characters in the count. This approach won't count multibyte characters correctly, though.
–
intuitedJun 8 '10 at 5:29

1

Also I think you need to escape the spaces, or just get rid of them.
–
intuitedJun 8 '10 at 6:04

Edited to include @intuited's suggestions, also appended to the statusline rather than overwrite it.
–
joeytwiddleJun 14 '14 at 21:40

If you're in the habit of using :w to save the file, each time you do this the status reports back the number of characters written. For instance, at the end of this sentence I did a :w (yes I'm using gvim to write this note) and it reported: 245C written.

I found out by accident that when I :w to save the file, the command outputs the number of bytes written. This is more or less a character count, so that's been close enough so far. I do like mrucci's answer as well, possibly more than this one because it has a word count too.