微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

vim设置go语言高亮

1. 配置go语言文件类型检测

mkdir -p ~/.vim/ftdetect/
echo 'au BufRead,BufNewFile *.go set filetype=go' > ~/.vim/ftdetect/go.vim

2. 配置go语言高亮

先确保 vimSyntax 目录已被创建:

mkdir -p ~/.vim/Syntax/

将如下内容添加~/.vim/Syntax/go.vim

文件内容是从此处获取的:PHP?script_id=2854">https://www.vim.org/scripts/s...
" Vim Syntax file
" Language:     Go
" Maintainer:   David Daub 
" Last Change:  2009 Nov 15
" Version:      0.1
"
" Early version. Took some (ok,most) stuff from existing Syntax files like
" c.vim or d.vim.
"
"
" Todo:
" - very much

" Quit when a (custom) Syntax file was already loaded
if exists("b:current_Syntax")
finish
endif

" A bunch of useful Go keywords
syn keyword goStatement select
syn keyword goStatement defer
syn keyword goStatement fallthrough range type
syn keyword goStatement return

syn keyword goClause import package
syn keyword goConditional if else switch
syn keyword goBranch goto break continue
syn keyword goLabel case default
syn keyword goRepeat for
syn keyword goType struct const interface func
syn keyword goType var map
syn keyword goType uint8 uint16 uint32 uint64
syn keyword goType int8 int16 int32 int64
syn keyword goType float32 float64
syn keyword goType float32 float64
syn keyword goType byte
syn keyword goType uint int float uintptr string

syn keyword goConcurrent chan go

syn keyword govalue nil
syn keyword goBoolean true false

syn keyword goConstant iota

" Builtin functions
syn keyword goBif len make new close closed cap map

" According to the language specification it is not garanteed to stay in the
" language. See http://golang.org/doc/go_spec.html#Bootstrapping
syn keyword goBif print println panic panicln

" Commants
syn keyword goTodo contained Todo FIXME XXX
syn match goLineComment "\/\/." contains=@Spell,goTodo
syn match goCommentSkip "^[ \t]
*($|[ \t]+)"
syn region goComment start="/*" end="*/" contains=@Spell,goTodo

" Numerals
syn case ignore
"integer number,or floating point number without a dot and with "f".
syn match goNumbers display transparent "\<\d|.\d" contains=goNumber,goFloat,goOctError,goOct
syn match goNumbersCom display contained transparent "\<\d|.\d" contains=goNumber,goOct
syn match goNumber display contained "\d+(u\=l{0,2}|ll\=u)>"

" hex number
syn match goNumber display contained "0x\x+(u\=l{0,2}|ll\=u)>"

" oct number
syn match goOct display contained "0\o+(u\=l{0,2}|ll\=u)>" contains=goOctZero
syn match goOctZero display contained "\<0"

syn match goFloat display contained "\d+.\d*(e[-+]\=\d+)\="
syn match goFloat display contained "\d+e[-+]\=\d\=>"
syn match goFloat display "(.[0-9]+)(e[-+]\=[0-9]+)\=[fl]\=i\=>"

" Literals
syn region goString start=+L\="+ skip=+\\|\"+ end=+"+ contains=@Spell

syn match goSpecial display contained "\(x\x+|\o{1,3}|.|$)"
syn match goCharacter "L\='[^\]'"
syn match goCharacter "L'[^']*'" contains=goSpecial

hi def link goStatement Statement
hi def link goClause Preproc
hi def link goConditional Conditional
hi def link goBranch Conditional
hi def link goLabel Label
hi def link goRepeat Repeat
hi def link goType Type
hi def link goConcurrent Statement
hi def link govalue Constant
hi def link goBoolean Boolean
hi def link goConstant Constant
hi def link goBif Function
hi def link goTodo Todo
hi def link goLineComment goComment
hi def link goComment Comment
hi def link goNumbers Number
hi def link goNumbersCom Number
hi def link goNumber Number
hi def link goFloat Float
hi def link goOct Number
hi def link goOctZero Number
hi def link goString String
hi def link goSpecial Special
hi def link goCharacter Character

let b:current_Syntax = "go"

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐