I want to add a function to my statusline by which I can display the total characters count of the current file.
:help statusline showed me that F referes to Full path to the file in the buffer, and through a bit searching I got to know how I can display the output of a shell command. So i currently have these in .vimrc:
set statusline+=%#lite#\ %o/%{DisplayTotalChars()}\
function! DisplayTotalChars()
let current_file = expand("%:F")
let total_chars = system('wc -c ' . current_file)
return total_chars
endfunction
This is what it displays now in the status line, whereas I only need the characters count not the file path to be displayed:
36/29488 /home/nino/scripts/gfp.py^@
That part is correct, minus the
\at the end which serves no purpose.That part is incorrect because the
Fyou found under:help 'statusline'means something when used directly in the value of&statuslinebut it is meaningless in:help expand(), where you are supposed to use:help filename-modifiers. The correct line would be:And a working function:
But your status line is potentially refreshed several times per second so calling an external program each time seems expensive.
Instead, you should scrap your whole function and use
:help wordcount()directly:which doesn't care about filenames or calling external programs.