2009-10-06 50 views
9

我閱讀了文檔,但更加困惑。
我已經編譯器生成以下錯誤:Vim errorformat

  rot; 
     ^
"cpp\c1.cpp", line 13: error(114): identifier 
      "rot" is undefined 


1 error detected in the compilation of "c1.cpp". 

我知道如何發現其中的錯誤行給出行,但我得到的額外的無用信息加載在我errorlist,錯誤消息分成兩行,我寧願合併。

我的出發錯誤格式運用於是:

:set efm=\"%f\"\\,\ line\ %l:\ error(%n):\ %m 

因爲我們是在它,有沒有測試EFM而不訴諸運行使所有的時間的快捷方式?

+1

什麼樣的東西是無用的信息?它是否來自實際的編譯器錯誤輸出,是由某個說明符錯誤地捕獲的?這也可以解釋雙線信息呢?如果這是有用的,默認值,從源頭(我無法在幫助中找到它):'「%f>%l:%c:%t:%n:%m,%f:% l:%t%* \\ D%n:%m,%f%l%t%* \\ D%n:%m,%* [^ \「] \」%f \「%* \\ D %1:%m,%f:%1:%m,%f |%l | %m「' – Cascabel 2009-10-06 13:54:02

回答

25

首先,我講調試。不幸的是,沒有特別容易做的方式,但一個有用的可能性是運行make吐輸出到一個文件,然後:

:let &makeprg="cat ~/outputfile.log" 
:make 

關於使得錯誤格式運用於,這確實需要有點試驗和錯誤。您可以使用%A,%C和%Z作爲多行消息,您可以使用%-G忽略某些內容。順序非常重要,請注意,有時%C甚至%Z會出現在%A之前!在你的情況下,你可能能夠在下面的efm處找到。我傾向於使用let &efm =let &efm .=而不是設置,因爲您不必逃避每個空格或引號,並且可以逐漸構建它。它也更具可讀性。

" Start of the multi-line error message (%A), 
" %p^ means a string of spaces and then a^to 
" get the column number 
let &efm = '%A%p^' . ',' 
" Next is the main bit: continuation of the error line (%C) 
" followed by the filename in quotes, a comma (\,) 
" then the rest of the details 
let &efm .= '%C"%f"\, line %l: error(%n): %m' . ',' 
" Next is the last line of the error message, any number 
" of spaces (' %#': equivalent to ' *') followed by a bit 
" more error message 
let &efm .= '%Z %#%m' . ',' 
" This just ignores any other lines (must be last!) 
let &efm .= '%-G%.%#' 
+6

+1爲調試提示。在Windows上,cat實用程序不可用的地方,可以使用':let&makeprg =」type outputfile.log「' – mMontu 2011-11-25 11:15:58

+1

根據您要更改'efm'的位置,您可以想要使用'let&l:efm ='而不是'let&efm ='來獲得'setlocal'等效的行爲,我特別想到了在一個文件類型插件或者類似的vim文件中 – 2016-07-22 16:16:01

+0

原來這是第一個真正的在我的C++代碼中使用空格而不是製表符的好理由,如果使用製表符並且編譯器輸出使用製表符,%p ^將失敗:( – Paul 2016-08-17 09:55:01