我想要向我的状态行添加一个函数,通过它我可以显示当前文件的字符总数。:help statusline向我展示了F引用Full path to the file in the buffer,通过一些搜索,我了解了如何显示shell命令的输出。所以我现在在.vimrc里有这些
set statusline+=%#lite#\ %o/%{DisplayTotalChars()}\
function! DisplayTotalChars()
let current_file = expand("%:F")
let total_chars = system('wc -c ' . current_file)
return total_chars
endfunction这就是它现在在状态栏中显示的内容,而我只需要字符计数,而不需要显示文件路径:
36/29488 /home/nino/script/gfp.py^@
发布于 2021-05-19 07:35:56
set statusline+=%#lite#\ %o/%{DisplayTotalChars()}\这个部分是正确的,减去最后的\,没有任何用途。
let current_file = expand("%:F")这个部分是不正确的,因为您在:help 'statusline'下找到的:help 'statusline'意味着在&statusline值中直接使用的东西,但是在:help expand()中它是没有意义的,在:help expand()中,您应该使用:help filename-modifiers。正确的行文是:
let current_file = expand("%:p")和一项工作职能:
function! DisplayTotalChars()
let current_file = expand("%:p")
let total_chars = system('wc -c ' . current_file)
return total_chars
endfunction但是状态线可能每秒刷新几次,因此每次调用外部程序似乎很昂贵。
相反,您应该放弃整个函数,直接使用:help wordcount():
set statusline+=%#lite#\ %o/%{wordcount().bytes}它不关心文件名或调用外部程序。
https://stackoverflow.com/questions/67597339
复制相似问题