【问题标题】:How-to handle errors in Vim Script?如何处理 Vim 脚本中的错误?
【发布时间】:2010-05-17 09:17:27
【问题描述】:

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

【问题讨论】:

    标签: vim folding


    【解决方案1】:

    我相信这可能会奏效:

    silent! 1;/\*\//fold
    

    【讨论】:

    • 我试过没有!,但没有用...添加它可以解决所有问题。非常感谢!
    猜你喜欢
    • 2019-05-23
    • 1970-01-01
    • 2014-05-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多