Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get length of current line

Tags:

vim

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?

like image 929
Ben Berman Avatar asked Mar 18 '16 16:03

Ben Berman


1 Answers

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('.'))}"
like image 178
Ben Berman Avatar answered Nov 15 '22 11:11

Ben Berman