I'm trying to add an indicator in my statusline for the total length of the line (not just the cursor column position, which can be shown with %c
). How do I do this?
To get the contents of a line as a string, use getline(<line number>)
.
To get the contents of the current line as a string, you can use getline(".")
.
To get the length of a string, you can use strlen(<string>)
.
Putting it all together, we get strlen(getline("."))
. To add it to your statusline, simply:
statusline += "%{strwidth(getline('.'))}"
or for vim-airline (what I use)
" can be any section; this is for section z (right hand side)
let g:airline_section_z = "%{strlen(getline('.'))}"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With