我想定义一个命令,该命令将首先构建当前Go源文件并加载 errors.err 文件,以便进一步使用:cnext或等命令:clist。
是)我有的:
我将以下行添加到我的.vimrc:
command Gobuild !go build %:t | grep -v "^\#" | tee errors.err
但我必须做:cfileafter :Gobuild,因为它不是自动完成的。如何自动加载errors.err文件?试图附加:cfile到命令,它没有帮助。加载后自动删除errors.err也很有用。
我知道有办法用 做这样的事情make,但我不喜欢它。
UPD:一个笨拙的临时解决方案(在我深入研究建议的解决方案之前):
function GoBuild()
silent !echo -e "make:\n\t@go 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