定义用于构建和加载错误文件的命令

I want to define a command that will first build the current Go source file and load errors.err file for further use of such commands as :cnext or :clist.

What I have:

I added the following line to my .vimrc:

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

But I have to do :cfile after :Gobuild, as it is not done automatically. How can I auto-load errors.err file? Tried to append :cfile to the command, it didn't help. Auto-removing of errors.err after it's loaded would be useful too.

I know there's a way to do something like this with make, but I don't like it.

UPD: a clumsy, termorary solution (before I dive into suggested solutions):

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

command Gobuild call GoBuild()

Here @ prevents make from echoing commands, grep filters out #command line arguments line, and tee is not to bother make with error code from grep (grep returns error code it there's noting to filter out) — tee always returns 0, OK error code.

UPD: a better solution

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

Generally speaking, the whole build and report errors business revolves around two options: 'makeprg' and 'errorformat' and a combination of :make and a bunch of quickfix-related commands like :copen or :cnext. Adding a couple of lines in your ~/.vimrc should be all you need.

This article as some sample code and here is a full-fledged plugin.