我想定義一個命令,它將首先構建當前的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
錯誤代碼從grep
(grep
返回錯誤代碼它有注意過濾掉) - tee
始終返回0,OK
錯誤代碼。
UPD:一個更好的解決方案
autocmd FileType go set makeprg=go\ build\ %:t\ 2>&1\\\|grep\ -v\ '^\\#'\\\|tee
command Gorun !./%:r
你不喜歡':make'? – romainl 2013-04-04 19:40:40
@romainl它會是什麼樣子?對我來說,工作下列: ':使SRC = 「%:T」' 而'makefile'是 '化妝:'' 去建立$ {SRC}' 但是長:make命令是不是很方便。而且我不想創建makefile,因爲我通常在隨機文件夾中構建隨機文件。 –
2013-04-04 19:50:52
@ o2genum您不需要創建任何makefile,請參閱':h'makeprg''。 – ZyX 2013-04-04 20:18:12