2013-04-04 13 views
0

我想定義一個命令,它將首先構建當前的Go源文件並加載errors.err文件,以便進一步使用:cnext:clist等命令。定義構建和加載錯誤的命令文件

我有什麼:

添加以下行到我的.vimrc

command Gobuild !go build %:t | grep -v "^\#" | tee errors.err 

但我:Gobuild後做:cfile,因爲它不會自動完成。如何自動加載errors.err文件?試圖追加:cfile到命令,它沒有幫助。加載後自動刪除errors.err也是有用的。

我知道有一種方法可以像make這樣做,但我不喜歡它。

UPD:笨拙,termorary溶液(前我潛入建議的解決方案):

function GoBuild() 
    silent !echo -e "make:\n\[email protected] build \${src} | grep -v '^\#' | tee" > %:t"_makefile" 
    make -f %:t"_makefile" src="%:t" 
    silent !rm %:t"_makefile" 
endfunction 

command Gobuild call GoBuild() 

這裏@防止make從呼應的命令,grep濾除#command line arguments線,並且tee是不要打擾make錯誤代碼從grepgrep返回錯誤代碼它有注意過濾掉) - tee始終返回0,OK錯誤代碼。

UPD:一個更好的解決方案

autocmd FileType go set makeprg=go\ build\ %:t\ 2>&1\\\|grep\ -v\ '^\\#'\\\|tee 
command Gorun !./%:r 
+1

你不喜歡':make'? – romainl 2013-04-04 19:40:40

+0

@romainl它會是什麼樣子?對我來說,工作下列: ':使SRC = 「%:T」' 而'makefile'是 '化妝:'' 去建立$ {SRC}' 但是長:make命令是不是很方便。而且我不想創建makefile,因爲我通常在隨機文件夾中構建隨機文件。 – 2013-04-04 19:50:52

+1

@ o2genum您不需要創建任何makefile,請參閱':h'makeprg''。 – ZyX 2013-04-04 20:18:12

回答

2

一般來說,整體構建和報告錯誤業務圍繞着兩個選擇:'makeprg''errorformat':make組合和像一堆的quickfix相關的命令:copen:cnext。在您的~/.vimrc中添加幾行應該是您所需要的。

This article作爲一些示例代碼和here is a full-fledged plugin

+0

最後更新(請參閱我的問題)是我用'makeprg'完成的。很好,謝謝。 – 2013-04-04 21:39:39

+1

這就是我想問的問題,當我問你不喜歡':make'時:你的基於':make'的解決方案是乾淨而堅實的。什麼不喜歡它? – romainl 2013-04-05 04:50:27

相關問題