donglu1472 2014-07-22 20:57
浏览 265

无法在Vim中自动格式化Go(golang)代码

I was having a problem with the following command:

autocmd FileType go autocmd BufWritePre <buffer> Fmt

its suppose to format my code code automatically by putting it at the end of my .vimrc file.

This is how my .vimrc file lookgs 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 'go.vim'

" 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

However, vim does throw me an error saying:

Error Detected while processing BufWrite Auto commands for "<buffer=1>"

E492: Not an editor command: Fmt

I have no idea whats wrong, specially because it was working earlier.

  • 写回答

1条回答 默认 最新

  • douyunjiaok300404 2014-07-24 06:26
    关注

    You're probably referring to the :Fmt command defined by this.

    It looks like that filetype plugin isn't sourced. You can check with the :scriptnames command; it needs to contain ftplugin/go/fmt.vim. If it isn't, something's wrong with your 'runtimepath' option.

    Alternatively, you could use fatih/vim-go; it apparently has a configuration that automatically formats the Go source code, so you don't need to define that :autocmd on your own.

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度