为VIM添加GoLang语法突出显示 [英] Add GoLang syntax highlighting for VIM

查看:171
本文介绍了为VIM添加GoLang语法突出显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Ubuntu上使用资源和方向将V语言语法突出显示添加到VIM中 http://go-lang.cat-v.org/text-editors/vim/



Go附带了一个 go.vim 包含VIM语法设置的文件,上述页面提供以下说明:

在〜/ .vim / syntax /中加入$ GOROOT / misc / vim / syntax / go.vim,并放入〜/ .vim / ftdetect / go.vim中:

  au BufRead,BufNewFile * .go set filetype = go 

这与我在其他地方看到的定制vim语法的过程大致相同
https://github.com/jnwhiteh/vim-golang/blob/master/readme.txt


所以我认为我在创建目录时做的是正确的事情:

〜/ .vim

〜/ .vim /语法

〜/ .vim / ftdetect



然后按照上面的说明加入

go.vim到〜/ .vim / syntax /
并在〜/ .vim / ftdetect /中创建一个文件go.vim,其中包含

  au BufRead,BufNewFile * .go set filetype = go 

然而,语法突出显示似乎没有发生。我需要做些什么来强制VIM查看这些新的设置文件?

你可以将这些行添加到你的〜/ .vimrc

  set rtp + = $ GOROOT / misc / vim 
filetype插件缩进
语法

编辑在这些行(即 .vimrc 文件的开头)之前,假定 filetype插件缩进并可能导致问题如果不是。请参阅下面的@ peterSO的回答以获取更安全的版本。


I'm trying to add Go language syntax highlighting to VIM on ubuntu with resources and direction supplied here http://go-lang.cat-v.org/text-editors/vim/.

Go comes with a go.vim file that contains syntax settings for VIM and the above page offers the following instructions

Place $GOROOT/misc/vim/syntax/go.vim in ~/.vim/syntax/ and put the following in ~/.vim/ftdetect/go.vim:

au BufRead,BufNewFile *.go set filetype=go 

This is more or less the same vein of procedure for customizing vim syntax I've seen elsewhere (Vim 7.3 on Ubuntu 12.10 doesn't have 'ftplugin' directory anywhere and https://github.com/jnwhiteh/vim-golang/blob/master/readme.txt)

So I think I'm doing the right thing when I create directories:
~/.vim
~/.vim/syntax
~/.vim/ftdetect

and follow the above instructions by adding

go.vim to ~/.vim/syntax/ and creating a file, go.vim, in ~/.vim/ftdetect/ which contains

au BufRead,BufNewFile *.go set filetype=go

Yet syntax highlighting does not seem to occur. Is there something I need to do to force VIM to look at these new settings files?

解决方案

you can just add these lines to your ~/.vimrc:

set rtp+=$GOROOT/misc/vim
filetype plugin indent on
syntax on

EDIT This assumes filetype plugin indent off before these lines (i.e. beginning of .vimrc file) and may cause problems if it's not. See @peterSO's answer below for the safer version.

这篇关于为VIM添加GoLang语法突出显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆