Vim和Cppcheck应使用哪种错误格式?

Vim和Cppcheck应使用哪种错误格式?,vim,cppcheck,Vim,Cppcheck,我使用以下脚本将Cppcheck与gVim集成: " vimcppcheck.vim " =================================================================== " Code Checking with cppcheck (1) " =================================================================== function! Cppcheck_1() set

我使用以下脚本将Cppcheck与gVim集成:

" vimcppcheck.vim
"  ===================================================================
"  Code Checking with cppcheck (1)
"  ===================================================================

function! Cppcheck_1()
  set makeprg=cppcheck\ --enable=all\ %
  setlocal errorformat=[%f:%l]:%m
  let curr_dir = expand('%:h')
  if curr_dir == ''
    let curr_dir = '.'
  endif
  echo curr_dir
  execute 'lcd ' . curr_dir
  execute 'make'
  execute 'lcd -'
  exe    ":botright cwindow"
  :copen
endfunction


:menu Build.Code\ Checking.cppcheck :cclose<CR>:update<CR>:call Cppcheck_1() <cr>
在大量Vim错误之后,在一个新的缓冲区中创建了一个新文件'11]->[test_cppcheck.c'。当我双击第一个错误时,quickfix窗口无法执行任何操作。这是因为据我所知的errorformat

->
而不是
造成了所有的麻烦,虽然我知道对这个脚本进行一些小的调整可以解决这个问题,但我已经厌倦了这样做


请先尝试此操作。我如何处理此问题?

如果没有错误的原始格式,这是猜测,但我认为您需要为
'errorformat'
定义添加一个替代选项(这些是逗号分隔的):


PS:您还应该为
'makeprg'
选项使用
:setlocal
,以将其限制为当前缓冲区。

现在我正在使用下面的脚本,它的工作与我预期的一样完美

对于所有有兴趣将Cppcheck与Vim集成的人来说,这是一个通用的解决方案

当然,这个脚本可以改进很多,但这是他们的一个起点

" vimcppcheck.vim
"  ===================================================================
"  Code Checking with cppcheck (1)
"  Thanks to Mr. Ingo Karkat
"  http://stackoverflow.com/questions/19157270/vim-cppcheck-which-errorformat-to-use
"  ===================================================================

function! Cppcheck_1()
  setlocal makeprg=cppcheck\ --enable=all\ %
  " earlier it was: " setlocal errorformat=[%f:%l]:%m
  " fixed by an advise by Mr. Ingo Karkat
  setlocal errorformat+=[%f:%l]\ ->\ %m,[%f:%l]:%m
  let curr_dir = expand('%:h')
  if curr_dir == ''
    let curr_dir = '.'
  endif
  echo curr_dir
  execute 'lcd ' . curr_dir
  execute 'make'
  execute 'lcd -'
  exe    ":botright cwindow"
  :copen
endfunction


:menu Build.Code\ Checking.cppcheck :cclose<CR>:update<CR>:call Cppcheck_1() <cr>
“vimcppcheck.vim
"  ===================================================================
“使用cppcheck进行代码检查(1)
“感谢英戈·卡尔卡特先生
"  http://stackoverflow.com/questions/19157270/vim-cppcheck-which-errorformat-to-use
"  ===================================================================
函数!Cppcheck_1()
setlocal makeprg=cppcheck\--enable=all\%
之前是:“setLocalErrorFormat=[%f:%l]:%m
“由Ingo Karkat先生的建议修正
setlocal errorformat+=[%f:%l]\->\%m,[%f:%l]:%m
让curr_dir=展开('%:h')
如果curr_dir==''
让curr_dir='。'
恩迪夫
回声电流方向
执行'lcd'。curr\u dir
执行“make”
执行'lcd-'
exe“:botright cwindow”
:科本
端功能
:menu Build.Code\Checking.cppcheck:cclose:update:call cppcheck_1()

非常感谢。这工作很好,非常棒,令人惊讶。但是我不知道如何使用:setlocal作为“makeprg”选项将其限制在当前缓冲区,但是我得到了我的答案。再次感谢。我只是说,在你的
Cppcheck_1()中
函数,将
set makeprg…
更改为
setlocal makeprg…
。谢谢,我会更改它。现在我将set makeprg…更改为setlocal makeprg…,现在我的脚本更加健壮,因为它不会意外打开新的缓冲区。谢谢。
|| Checking test_cppcheck.c...
H:\codes\test_cppcheck.c:11] -> [test_cppcheck.c|12| (warning) Possible null pointer dereference: ptr01 - otherwise   it is redundant to check it against null.
H:\codes\test_cppcheck.c|11| (error) Uninitialized variable: ptr01
H:\codes\test_cppcheck.c|16| (error) Uninitialized variable: ptr01
H:\codes\test_cppcheck.c|12| (error) Uninitialized variable: ptr01
|| Checking usage of global functions..
|| (information) Cppcheck cannot find all the include files (use --check-config for details)
setlocal errorformat=[%f:%l]\ ->\ %m,[%f:%l]:%m
" vimcppcheck.vim
"  ===================================================================
"  Code Checking with cppcheck (1)
"  Thanks to Mr. Ingo Karkat
"  http://stackoverflow.com/questions/19157270/vim-cppcheck-which-errorformat-to-use
"  ===================================================================

function! Cppcheck_1()
  setlocal makeprg=cppcheck\ --enable=all\ %
  " earlier it was: " setlocal errorformat=[%f:%l]:%m
  " fixed by an advise by Mr. Ingo Karkat
  setlocal errorformat+=[%f:%l]\ ->\ %m,[%f:%l]:%m
  let curr_dir = expand('%:h')
  if curr_dir == ''
    let curr_dir = '.'
  endif
  echo curr_dir
  execute 'lcd ' . curr_dir
  execute 'make'
  execute 'lcd -'
  exe    ":botright cwindow"
  :copen
endfunction


:menu Build.Code\ Checking.cppcheck :cclose<CR>:update<CR>:call Cppcheck_1() <cr>