vim - 使用 Vim :make with quickfix ends up creating a new file when error is in header

标签 vim makefile buffer

我使用 Vim 进行了设置,我可以在其中使用 :make 编译我的 C/C++ 代码,并且编译错误会使用我的 ./vimrc 中的以下行 (from the Vim wiki) 自动显示在快速修复窗口中:

" 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

即 vim 正确切换到 LatticeModel.cpp

但是,如果错误在 头文件 中,则 make 输出会被误解,并且 vim 会切换/创建一个名为“make ”的新缓冲区(对于以下示例 In file included from IsingMain.cpp 输出),显然错误地假设这是带有错误(实际上错误在 LatticeModel.h 中):
$ make
g++    -c -o IsingMain.o IsingMain.cpp
In file included from IsingMain.cpp:2:0:
LatticeModel.h:31:5: error: ‘Zvoid’ does not name a type

从命令行运行 make 效果很好,这只是 quickfix 误读了它的输出的问题。非常感谢任何帮助,让我知道这是否有任何部分令人困惑。谢谢

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

编辑 2 :通过使用 this technique 忽略以“In file contains from”开头的 make 输出行找到的临时修复。

最佳答案

虽然我还没有找到合适的解决方案,但这里建议的解决方法是:http://groups.google.com/group/vim_dev/msg/ed4f258f5b4b9749
似乎暂时有效。

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

编辑 :另见 Vim tries to jump to nonexistent file after :make

关于vim - 使用 Vim :make with quickfix ends up creating a new file when error is in header,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6747337/

相关文章:

vim - 如何更改默认 ESC 以退出 LightTable 的 Vim 中的插入模式?

vim - 如何在Vim中按字母顺序排列CSS文件

java - 缓冲写入器未写入文件

c++ - 在 C++ 中将方法放入缓冲区

c - 内存、缓冲区和堆栈有什么区别?

apache-flex - Adobe Flash Builder 4 的 VIM 键绑定(bind)

Go 的 Vim makeprg 和错误格式

c++ - 体系结构 x86_64 的 undefined symbol ,链接器命令失败

python - 为什么这个 Makefile 每次都要重建?

php - 创建像 XAMPP 这样的自定义 LAMP 发行版