Vim插件之syntastic

来源:互联网 发布:逆波兰表达式 c语言 编辑:程序博客网 时间:2024/05/15 23:47

已经转投ale,具体看这里
syntastic是Vim上比较老牌的一款语法检查插件,虽然性能不及ale,但兼容性要更好一些,配置如下

"syntastic"设置error和warning的标志let g:syntastic_enable_signs = 1let g:syntastic_error_symbol='✗'let g:syntastic_warning_symbol='►'"总是打开Location List(相当于QuickFix)窗口,如果你发现syntastic因为与其他插件冲突而经常崩溃,将下面选项置0let g:syntastic_always_populate_loc_list = 1"自动打开Locaton List,默认值为2,表示发现错误时不自动打开,当修正以后没有再发现错误时自动关闭,置1表示自动打开自动关闭,0表示关闭自动打开和自动关闭,3表示自动打开,但不自动关闭let g:syntastic_auto_loc_list = 1"修改Locaton List窗口高度let g:syntastic_loc_list_height = 5"打开文件时自动进行检查let g:syntastic_check_on_open = 1"自动跳转到发现的第一个错误或警告处let g:syntastic_auto_jump = 1"进行实时检查,如果觉得卡顿,将下面的选项置为1let g:syntastic_check_on_wq = 0"高亮错误let g:syntastic_enable_highlighting=1"让syntastic支持C++11let g:syntastic_cpp_compiler = 'clang++'let g:syntastic_cpp_compiler_options = ' -std=c++11 -stdlib=libc++'"设置pyflakes为默认的python语法检查工具let g:syntastic_python_checkers = ['pyflakes']"修复syntastic使用:lnext:lprev出现的跳转问题,同时修改键盘映射使用sn和sp进行跳转function! <SID>LocationPrevious()                         try                                                       lprev                                                 catch /^Vim\%((\a\+)\)\=:E553/                            llast                                                 endtry                                                endfunction                                             function! <SID>LocationNext()                             try                                                       lnext                                                 catch /^Vim\%((\a\+)\)\=:E553/                            lfirst                                                endtry                                                endfunction                                             nnoremap <silent> <Plug>LocationPrevious    :<C-u>exe 'call <SID>LocationPrevious()'<CR>                                        nnoremap <silent> <Plug>LocationNext        :<C-u>exe 'call <SID>LocationNext()'<CR>nmap <silent> sp    <Plug>LocationPrevious              nmap <silent> sn    <Plug>LocationNext"关闭syntastic语法检查, 鼠标复制代码时用到, 防止把错误标志给复制了nnoremap <silent> <Leader>ec :SyntasticToggleMode<CR>function! ToggleErrors()    let old_last_winnr = winnr('$')    lclose    if old_last_winnr == winnr('$')        " Nothing was closed, open syntastic error location panel        Errors    endifendfunction

因为默认情况下syntastic并不支持对C++11进行语法检查,因此上面使用了clang来解决这个问题,clang相比gcc提供的错误信息更加友好,如果你习惯gcc的话,将上面的

let g:syntastic_cpp_compiler = 'clang++'let g:syntastic_cpp_compiler_options = ' -std=c++11 -stdlib=libc++'

替换为

let g:syntastic_cpp_checkers = ['gcc']let g:syntastic_cpp_compiler = 'gcc'let g:syntastic_cpp_compiler_options = '-std=c++11'

另外,使用时,如果你想临时手动关闭syntastic的Location List输入:lclose即可

0 0