문제

In my .vimrc file, I have the following function, which folds the licensing information on the top of some .hpp and .cpp files:

" 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()

This works well, but if I open a .cpp file which doesn't have any licensing information block, Vim complains that the pattern is not found. Fair enough, but is there a way so that he stops complaining and just does nothing if the pattern is not found ?

Thanks !

Edit: complete solution (using Bryan Ross answer)

" 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()
도움이 되었습니까?

해결책

I believe this might work:

silent! 1;/\*\//fold
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top