Vim的makeprg和errorformat用于Go语言。

huangapple go评论120阅读模式
英文:

Vim makeprg and errorformat for Go

问题

我想要能够在vim中构建和运行Go代码,并在编译错误时访问quickfix窗口。

为了实现与Java类似的功能,我在我的.vimrc文件中添加了以下内容:

autocmd Filetype java set makeprg=ant\ -find\ build.xml
autocmd Filetype java set efm=%A\ %#[javac]\ %f:%l:\ %m,%-Z\ %#[javac]\ %p^,%-C%.%#

我目前在我的.vimrc文件中为Go设置了以下内容:

autocmd Filetype go set makeprg=go\ run

我应该添加什么内容,使得:make(或者:make %)的行为像对一个良好的C程序一样,具有漂亮的错误报告和在缓冲区下方的输出?

英文:

I would like to be able to build and run Go code from within vim with access to quickfix window if there are compilation errors.

To achieve something close to this with Java I added the following to my .vimrc:

autocmd Filetype java set makeprg=ant\ -find\ build.xml
autocmd Filetype java set efm=%A\ %#[javac]\ %f:%l:\ %m,%-Z\ %#[javac]\ %p^,%-C%.%#

I have the following currently for Go in my .vimrc:

autocmd Filetype go set makeprg=go\ run

What can I have to make :make (or :make %) act like it would for a good 'ol C program with pretty error reporting and output below the buffer?

答案1

得分: 4

对于当前工作目录只包含一个程序或库的情况,可以使用以下Vim命令:

autocmd Filetype go set makeprg=go\ build

如果只想编译一个文件,可以使用以下命令覆盖上述设置:

:set makeprg=go\ build\ hello.go

更多信息可以在jnwhiteh的vim-golang中找到。

英文:

For cases where your current working directory consists of a single program or library, the following works fine with Vim:

autocmd Filetype go set makeprg=go\ build

For cases where there is just one file you want to compile, I override this with:

:set makeprg=go\ build\ hello.go

More can be found at jnwhiteh's vim-golang.

huangapple
  • 本文由 发表于 2012年6月15日 05:15:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/11041462.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定