I want to configure the statusbar in vim to show which row I'm on. I have it currently set as

statusline=%l/%L\ (%3p%%)

I want however to do something like the following

statusline=%3l/%3L\ (%3p%%)

The problem is that I don't know how big %L is going to be before hand. Can I somehow do

statusline=%{length of L}l/%L\ (%3p%%)

so that l is always printed with the same size as L?

1 Answer 1


See :help statusline where you can find many forms of embedding expressions, including %!, %{, and %{%. In this case, I might use %{% with an expression that calculates the length of %L (via line('$')->len()) and returns the expression '%'.length_L.'l':

:set statusline=%{%'%'.(line('$')->len()).'l'%}/%L\ (%3p%%)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.