How do I handle errors in Vim Script?

In my file .vimrc

, I have the following function that adds licensing information at the top of some files .hpp

and .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()

      

This works well, but if I open a file .cpp

that does not have , has any block of licensing information, Vim complains that the template was not found. Fair enough, but is there a way for it to stop complaining and do nothing if the pattern is not found?

Thanks!

Edit: complete solution (using Brian 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 source to share


1 answer


I believe this might work:



silent! 1;/\*\//fold

      

+4


a source







All Articles