使用Vim:make with quickfix会在头中出现错误时创建一个新文件

使用Vim:make with quickfix会在头中出现错误时创建一个新文件,vim,makefile,buffer,Vim,Makefile,Buffer,我已经使用Vim进行了设置,可以使用:make编译我的C/C++代码,编译错误会自动显示在快速修复窗口中,使用我的/vimrc中的以下行: " Automatically open, but do not go to (if there are errors) the quickfix / " location list window, or close it when is has become empty. " " Note: Must allow nesting of autocmds

我已经使用Vim进行了设置,可以使用
:make
编译我的C/C++代码,编译错误会自动显示在快速修复窗口中,使用我的
/vimrc
中的以下行:

" Automatically open, but do not go to (if there are errors) the quickfix /
" location list window, or close it when is has become empty. 
"
" Note: Must allow nesting of autocmds to enable any customizations for quickfix
" buffers. 
" Note: Normally, :cwindow jumps to the quickfix window if the command opens it
" (but not if it's already open). However, as part of the autocmd, this doesn't
" seem to happen. 
autocmd QuickFixCmdPost [^l]* nested cwindow
autocmd QuickFixCmdPost    l* nested lwindow
现在,如果.cpp文件中存在错误,此设置工作正常,因为make的输出已正确解析:

$ make
g++    -c -o IsingMain.o IsingMain.cpp
g++    -c -o LatticeModel.o LatticeModel.cpp
LatticeModel.cpp: In member function ‘void LatticeModel::initialiseSystem()’:
LatticeModel.cpp:18:25: error: ‘sirand’ was not declared in this scope
i、 e.vim正确切换到
latticeCodel.cpp


但是,如果错误出现在头文件中,make输出会被误解,vim会切换/创建一个名为“
的新缓冲区(对于下面的示例
make
output),该缓冲区在IsingMain.cpp
中包含的文件中,显然是错误地假定这是有错误的文件(事实上,错误在LatticeModel.h中):

从命令行运行make工作得非常好,这只是quickfix误读其输出的问题。非常感谢您的帮助,如果其中有任何部分令人困惑,请告诉我。谢谢

编辑:这似乎与错误的错误格式有关(如中所述)


编辑2:通过忽略以“In file included from”开头的make输出行找到临时修复方法。

虽然我还没有找到合适的解决方案,但这里建议的解决方法是: 似乎暂时有效

set errorformat^=%-GIn\ file\ included\ %.%# 

编辑:另请参见

几个问题:-它最终会创建什么文件?;-当前路径是什么?文件的路径是什么?;-您使用的是什么版本的vim(cygwin或win32)?;-您使用的是什么版本的gcc(TDM/mingw或cygwin)?;-从哪里启动vim(bash或windows资源管理器)?@Luc Hermitte-它最终创建了一个缓冲区(除非保存,否则不会实际创建文件),该缓冲区的全名
(包含空格)包含在IsingMain.cpp中的文件中.我在Ubuntu上使用的是Vim 7.3和gcc 4.5.2.?Vim与源文件和makefile在同一个目录下运行。好的,这个名称很重要。错误消息介绍似乎被解释为一个文件名。我会在Vim邮件列表上询问。这是最好的地方。如果有解决方案,可以通过这种方式集成否则,看看
:h'efm'
,解决方案在于调整此选项,如果您想自己解决它(我不太擅长调整此选项^^')@Luc Hermitte-好,很有意思。似乎包括一行忽略以“in file included with”开头的行,所以不知道为什么不起作用。现在就试着解码那个可怕的字符串!
set errorformat^=%-GIn\ file\ included\ %.%#