tags:

views:

28

answers:

1

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()
+2  A: 

I believe this might work:

silent! 1;/\*\//fold
Bryan Ross
I had a try without the `!` which didn't worked... Adding it solves everything. Many thanks !
ereOn