Ricky

链接

RSS

RSS Link
搭建基于Vim的Go IDE
Gocode不能弹出补全菜单的问题

在Vim中调用Go编译程序,并将错误用quickfix定位

Ricky posted @ 2012年4月28日 21:27 in Vim , 6843 阅读

配置go文件对应的compiler, 在ftplugin/go.vim加入一行:

compiler go

配置编译程序和quickfix读入编译结果的格式, 在$VIMRUNTIME/compiler新建go.vim并加入如下行:


" Vim compiler file
" Compiler:     go
" Maintainer:   Ricky Wu <rickywu1113 at gmail dot com>
" URL:          richiewu.i11r.com               
" Last Change:  2012 May 2

if exists("current_compiler")
  finish
endif
let current_compiler = "go"

let s:cpo_save = &cpo
set cpo-=C

if exists(":CompilerSet") != 2          " older Vim always used :setlocal
  command -nargs=* CompilerSet setlocal <args>
endif

"Compiler program
CompilerSet makeprg=go\ build

"Compiler error format for go build
CompilerSet errorformat=%f:%l:%m

let &cpo = s:cpo_save
unlet s:cpo_save

这样:make命令将会编译当前文件并用quickfix打开错误列表以定位错误行。

Head_small
邱焜 说:
2012年6月08日 21:30

:make 之后要 :cc 才有 quickfix

Avatar_small
Ricky 说:
2012年7月03日 11:00

autocmd QuickFixCmdPre * :update
autocmd QuickFixCmdPost * :copen
autocmd FileType qf call AdjustWindowHeight(2, 6)

我用这三个命令,make前先保存文件,make后自动打开quickfix,然后调整quickfix窗口高度

Avatar_small
Reckhou 说:
2013年6月13日 15:09

这个脚本有些问题,首先$GOPATH中存在多个路径时,脚本只会选取其中一个路径去找package,因此会导致无法正确获取依赖关系报错。

其次,如果引用的package中有引用其它第三方package(如github上的),这个脚本同样无法正确识别。

实际上用Syntastic已经可以完全替代这个脚本了。

Avatar_small
Ricky 说:
2013年6月17日 16:19

Syntastic不是个语法检查的插件吗,能检查出所有的语法和编译错误?

我好久没用go了,这个脚本只是调用go命令而已,命令行怎样编译,这个脚本也怎样编译,只负责调用而已,如果要指定参数只需要修改CompilerSet makeprg=go\ build

Avatar_small
Reckhou 说:
2013年6月17日 16:22

Syntastic同样可以检查出编译错误,和编译是一样的过程。

Avatar_small
Independent Delhi Es 说:
2021年8月12日 20:34

It is very much useful for new users who are new to programming. You will learn lots of things here through this website.

Avatar_small
Chennai Escorts Serv 说:
2022年11月07日 18:25

The Service that the girls provide here is an great with the Model Escorts Service in Chennai and explore the things here for the change.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter