问题
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?
回答1:
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
let g:ariline_section_z = "%{strlen(getline('.'))}"
来源:https://stackoverflow.com/questions/36089968/get-length-of-current-line