Get length of current line

北慕城南 提交于 2020-01-24 05:25:06

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!