如何处理Vim脚本中的错误?

时间:2010-05-17 09:17:27

标签: vim folding

在我的.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()

1 个答案:

答案 0 :(得分:4)

我相信这可行:

silent! 1;/\*\//fold
相关问题