什么是“autocmd FileType go编译器去”应该做什么?

时间:2014-07-22 22:38:16

标签: vim go

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

我尝试的是执行$GOROOT/misc/vim中readme.txt文件中的说明。它有以下建议:

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

保存文件时,

不执行任何操作。该怎么办?我的代码中显然有错误:

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文件的样子:

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有没有办法在保存或其他方面做到这一点?

1 个答案:

答案 0 :(得分:1)

autocmd FileType go compiler go

只告诉Vim在执行:make时要使用哪些编译器和设置。您可以在:compiler和关联的:help :compiler中了解:help write-compiler-plugin

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

请注意,~/.vimrc中评论的Syntastic插件附带Go支持,并在写入时发挥其魔力。

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