在我的.vimrc
文件中,我有以下功能,它将许可信息折叠在一些文件.hpp
的顶部:.cpp
" Skip license
function! FoldLicense()
if !exists("b:foldedLicense")
let b:foldedLicense = 1
1;/\*\//fold
endif
endfunction
au BufRead *.hpp call FoldLicense()
au BufRead *.cpp call FoldLicense()
这很好用,但是如果我打开一个没有.cpp
任何许可信息块的文件,Vim 会抱怨找不到模式。很公平,但是有没有办法让他停止抱怨,如果找不到模式,什么也不做?
谢谢 !
编辑:完整的解决方案(使用 Bryan Ross 的回答)
" Skip license
function! FoldLicense()
if !exists("b:foldedLicense")
let b:foldedLicense = 1
silent! 1;/\*\//fold
endif
endfunction
au BufRead *.hpp call FoldLicense()
au BufRead *.cpp call FoldLicense()