2

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

1 回答 1

5

我相信这可能有效:

silent! 1;/\*\//fold
于 2010-05-17T09:27:04.830 回答