Question

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()
Was it helpful?

Solution

I believe this might work:

silent! 1;/\*\//fold
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top