首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >"autocmd FileType go编译器go“应该做什么?

"autocmd FileType go编译器go“应该做什么?
EN

Stack Overflow用户
提问于 2014-07-23 06:38:16
回答 1查看 762关注 0票数 1

我试图在vim中添加插件静态分析我当前的go (golang)文件并捕获错误的功能。

我尝试的是在$GOROOT/misc/vim中执行readme.txt文件中的指令。在那里,它有以下建议:

代码语言:javascript
复制
Vim compiler plugin
-------------------

To install the compiler plugin:

  1. Same as 1 above.
  2. Copy or link compiler/go.vim to the compiler directory underneath your vim
     runtime directory (normally $HOME/.vim/compiler).
  3. Activate the compiler plugin with ":compiler go". To always enable the
     compiler plugin in Go source files add an autocommand to your .vimrc file
     (normally $HOME/.vimrc):

     autocmd FileType go compiler go


Godoc plugin
------------

我照他们说的做了,但是:

autocmd FileType go compiler go

当我保存我的文件时不做任何事情。它应该做什么呢?显然,我的代码中有错误:

代码语言:javascript
复制
package main

import "fmt"

//This is my first go program!
//cool hu? Hope I can render this.
func main(){
jhjkahsdjkh //<-----------------ERROR HERE
        fmt.Print("Hello World\n")
}

我不知道会发生什么,因为我不知道autocmd FileType go compiler go应该做什么。

这是我的vim文件的样子:

代码语言:javascript
复制
set nocompatible              " be iMproved, required
filetype off                  " required

" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')

" let Vundle manage Vundle, required
Plugin 'gmarik/Vundle.vim'

" Keep Plugin commands between vundle#begin/end.
" plugin on GitHub repo
Plugin 'tpope/vim-fugitive'
" plugin from http://vim-scripts.org/vim/scripts.html
Plugin 'L9'
" Git plugin not hosted on GitHub
Plugin 'git://git.wincent.com/command-t.git'
" git repos on your local machine (i.e. when working on your own plugin)
Plugin 'file:///home/gmarik/path/to/plugin'
" The sparkup vim script is in a subdirectory of this repo called vim.
" Pass the path to set the runtimepath properly.
Plugin 'rstacruz/sparkup', {'rtp': 'vim/'}
" Avoid a name conflict with L9
Plugin 'user/L9', {'name': 'newL9'}
Plugin 'commentary.vim'
"Plugin 'fatih/vim-go'
"Plugin 'Syntastic'

" All of your Plugins must be added before the following line
call vundle#end()            " required
filetype plugin indent on    " required
""""------------------------------------
 syntax on
" filetype plugin on
" filetype indent on

 autocmd FileType go compiler go
" autocmd FileType go autocmd BufWritePre <buffer> Fmt

我也尝试了一下,安装了'fatih/vim-go‘插件并执行了:GoBuild命令。这有点用,但我并不是指向当前文件中的错误,而是转到其他包中的其他文件,这些文件正在开发中,显然有错误,但我不想看到这些,我只想看到当前文件中的错误。有没有插件可以做到这一点?有没有办法让我的vim在保存的时候做这件事呢?

EN

回答 1

Stack Overflow用户

发布于 2014-07-23 15:49:52

代码语言:javascript
复制
autocmd FileType go compiler go

只告诉Vim在执行:make时要使用什么编译器和设置。您可以在:help :compiler和链接的:help write-compiler-plugin中阅读有关:compiler的内容。

如果希望Vim显示代码中的错误,则需要发出:make命令。

请注意,~/.vimrc中注释的Syntastic插件支持Go,并在编写时发挥了它的魔力。

看起来你安装了相当多与go相关的插件,这可能会让你的生活变得更加复杂。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24899059

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档