2
我嘗試使用F4添加作者和其他信息。VIM獲取E488尾隨字符
但是當我打開* .c或其他文件(非* .sh),並且推F4時,它將顯示E488尾隨字符。
此外,當試圖更新信息時,它符合E20標記未設置。
而更多的問題,當我嘗試使用 let suff = expand("%:e")
獲取Java文件擴展名,然後if suff == "java"
,發現SUFF不等於「Java」的,爲什麼呢?
這是我的VIM配置:
" Add Author Information
map <F4> :call TitleDet()<CR>'s
function AddTitle()
call append(0,"/*========================================")
call append(1,"#")
call append(2,"# Author: xxx ")
call append(3,"#")
call append(4,"# Email: [email protected]")
call append(5,"#")
call append(6,"# Last modified: ".strftime("%Y-%m-%d %H:%M"))
call append(7,"#")
call append(8,"# Filename: ".expand("%:t"))
call append(9,"#")
call append(10,"# Description: ")
call append(11,"#")
call append(12,"======================================*/")
call append(13,"");
echohl WarningMsg | echo "Successful in adding the copyright." | echohl None
endfunction
function AddShellTitle()
call append(0,"#=========================")
call append(1,"#")
call append(2,"# Author: xxx")
call append(3,"#")
call append(4,"# Email: xxx")
call append(5,"#")
call append(6,"# Last modified: ".strftime("%Y-%m-%d %H:%M"))
call append(7,"#")
call append(8,"# Filename: ".expand("%:t"))
call append(9,"#")
call append(10,"# Description: ")
call append(11,"#")
call append(12,"#========================")
echohl WarningMsg | echo "Successful in adding the copyright." | echohl None
endfunction
function UpdateTitle()
normal m'
execute '/# *Last modified:/[email protected]:.*[email protected]\=strftime(": %Y-%m-%d %H:%M")@'
normal ''
normal mk
execute '/# *Filename:/[email protected]:.*[email protected]\=": ".expand("%:t")@'
execute "noh"
normal 'k
echohl WarningMsg | echo "Successful in updating the copy right." | echohl None
endfunction
function UpdateShellTitle()
normal m'
execute '/" *Last modified:/[email protected]:.*[email protected]\=strftime(": %Y-%m-%d %H:%M")@'
normal ''
normal mk
execute '/" *Filename:/[email protected]:.*[email protected]\=": ".expand("%:t")@'
execute "noh"
normal 'k
echohl WarningMsg | echo "Successful in updating the copy right." | echohl None
endfunction
function TitleDet()
let n=1
let suff = expand("%:e")
while n < 10
let line = getline(n)
if suff != "sh"
if line =~ '^\#\s*\S*Last\smodified:\S*.*$'
call UpdateTitle()
return
endif
else
if line =~ '^\#\s*\S*Last\smodified:\S*.*$'
call UpdateShellTitle()
return
endif
endif
let n = n + 1
endwhile
if suff != "sh"
call AddTitle()
else
call AddShellTitle()
endif
endfunction
請代碼減少到具有實際問題的一部分。這個問題太本地化了。 – sehe