首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法在vim中自动格式化go (golang)代码

无法在vim中自动格式化go (golang)代码
EN

Stack Overflow用户
提问于 2014-07-23 04:57:39
回答 1查看 3.1K关注 0票数 3

我在使用以下命令时遇到了问题:

autocmd FileType go autocmd BufWritePre <buffer> Fmt

它假定通过将代码放在.vimrc文件的末尾来自动格式化代码。

下面是我的.vimrc文件的外观:

代码语言: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 '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

然而,vim确实抛给我一个错误,说:

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

E492: Not an editor command: Fmt

我不知道出了什么问题,特别是因为它之前是有效的。

EN

回答 1

Stack Overflow用户

发布于 2014-07-24 14:26:35

您可能指的是由this定义的:Fmt命令。

看起来那个文件类型插件不是源码的。您可以使用:scriptnames命令进行检查;它需要包含ftplugin/go/fmt.vim。如果不是,则说明您的'runtimepath'选项有问题。

或者,您可以使用fatih/vim-go;它显然具有自动格式化Go源代码的配置,因此您不需要自己定义该:autocmd

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

https://stackoverflow.com/questions/24897703

复制
相关文章

相似问题

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