0
我想在我的.vimrc文件中添加一個函數,該函數更新打開的文檔中的文本,特別是它找到文本「字數」的文本:它將使用vim插入一個精確當前文檔中的字數。在Vim文檔中打印的字數
這主要是作爲一個編程練習和更好地學習vim,我知道有像wc這樣的外部程序可以完成這項工作。
下面是我用數行代碼的類似功能的例子:
function! CountNonEmpty()
let l = 1
let char_count = 0
while l <= line("$")
if len(substitute(getline(l), '\s', '', 'g')) > 3
let char_count += 1
endif
let l += 1
endwhile
return char_count
endfunction
function! LastModified()
if &modified
let save_cursor = getpos(".")
let n = min([15, line("$")])
keepjumps exe '1,' . n . 's#^\(.\{,10}LOC:\).*#\1' .
\ ' ' . CountNonEmpty() . '#e'
call histdel('search', -1)
call setpos('.', save_cursor)
endif
endfun
autocmd BufWritePre * call LastModified()
有人可以幫助我弄清楚如何添加到上次更改功能,使得它插入一個字計數的地方在標題中找到文字字數?