douhuo1738 2014-07-22 22:38
浏览 166

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

I was trying to add the functionality that a plugin in vim statically analyses my current go (golang) file and catches errors.

What I tried was doing the instructions in the readme.txt file in $GOROOT/misc/vim. There it had the following suggestion:

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
------------

I did all they said but:

autocmd FileType go compiler go

doesn't do anything when I save my file. What is it supposed to do? I clearly have errors in my code:

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
")
}

I don't know what to expect cuz I don't know what autocmd FileType go compiler go is supposed to do.

This is how my vim file looks like:

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

I also tried this by installing 'fatih/vim-go' plugin and doing the command :GoBuild. That kind of worked, but instead of pointing me to my errors in the current file in went to other files in other packages to that are in development and obviously have errors, but I don't want to see those, I only want to see the errors in my current file. Is there a plugin that does this? Is there a way for my vim to do this on save or something?

  • 写回答

1条回答 默认 最新

  • dsfsdfsd34324 2014-07-23 07:49
    关注
    autocmd FileType go compiler go
    

    only tells Vim what compiler and settings to use when doing :make. You can read about :compiler in :help :compiler and the linked :help write-compiler-plugin.

    If you want Vim to show errors in your code, you need to issue the :make command.

    Note that the Syntastic plugin, that's commented in your ~/.vimrc, comes with Go support and does its magic on write.

    It looks like you are installing quite a lot of go-related plugins and, possibly, making your life more complicated than it should.

    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分