vim设置go语言高亮

前端之家收集整理的这篇文章主要介绍了vim设置go语言高亮前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

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

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

2. 配置go语言高亮

先确保 vimSyntax 目录已被创建:

  1. mkdir -p ~/.vim/Syntax/

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

文件内容是从此处获取的:PHP?script_id=2854">https://www.vim.org/scripts/s...
  1. " Vim Syntax file
  2. " Language: Go
  3. " Maintainer: David Daub
  4. " Last Change: 2009 Nov 15
  5. " Version: 0.1
  6. "
  7. " Early version. Took some (ok,most) stuff from existing Syntax files like
  8. " c.vim or d.vim.
  9. "
  10. "
  11. " Todo:
  12. " - very much
  13. " Quit when a (custom) Syntax file was already loaded

  14. if exists("b:current_Syntax")

  15. finish

  16. endif

  17. " A bunch of useful Go keywords

  18. syn keyword goStatement select

  19. syn keyword goStatement defer

  20. syn keyword goStatement fallthrough range type

  21. syn keyword goStatement return

  22. syn keyword goClause import package

  23. syn keyword goConditional if else switch

  24. syn keyword goBranch goto break continue

  25. syn keyword goLabel case default

  26. syn keyword goRepeat for

  27. syn keyword goType struct const interface func

  28. syn keyword goType var map

  29. syn keyword goType uint8 uint16 uint32 uint64

  30. syn keyword goType int8 int16 int32 int64

  31. syn keyword goType float32 float64

  32. syn keyword goType float32 float64

  33. syn keyword goType byte

  34. syn keyword goType uint int float uintptr string

  35. syn keyword goConcurrent chan go

  36. syn keyword goValue nil

  37. syn keyword goBoolean true false

  38. syn keyword goConstant iota

  39. " Builtin functions

  40. syn keyword goBif len make new close closed cap map

  41. " According to the language specification it is not garanteed to stay in the

  42. " language. See http://golang.org/doc/go_spec.html#Bootstrapping

  43. syn keyword goBif print println panic panicln

  44. " Commants

  45. syn keyword goTodo contained TODO FIXME XXX

  46. syn match goLineComment "\/\/." contains=@Spell,goTodo

  47. syn match goCommentSkip "^[ \t]*($|[ \t]+)"

  48. syn region goComment start="/*" end="*/" contains=@Spell,goTodo

  49. " Numerals

  50. syn case ignore

  51. "integer number,or floating point number without a dot and with "f".

  52. syn match goNumbers display transparent "\<\d|.\d" contains=goNumber,goFloat,goOctError,goOct

  53. syn match goNumbersCom display contained transparent "\<\d|.\d" contains=goNumber,goOct

  54. syn match goNumber display contained "\d+(u\=l{0,2}|ll\=u)>"

  55. " hex number

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

  57. " oct number

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

  59. syn match goOctZero display contained "\<0"

  60. syn match goFloat display contained "\d+.\d*(e[-+]\=\d+)\="

  61. syn match goFloat display contained "\d+e[-+]\=\d\=>"

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

  63. " Literals

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

  65. syn match goSpecial display contained "\(x\x+|\o{1,3}|.|$)"

  66. syn match goCharacter "L\='[^\]'"

  67. syn match goCharacter "L'[^']*'" contains=goSpecial

  68. hi def link goStatement Statement

  69. hi def link goClause Preproc

  70. hi def link goConditional Conditional

  71. hi def link goBranch Conditional

  72. hi def link goLabel Label

  73. hi def link goRepeat Repeat

  74. hi def link goType Type

  75. hi def link goConcurrent Statement

  76. hi def link goValue Constant

  77. hi def link goBoolean Boolean

  78. hi def link goConstant Constant

  79. hi def link goBif Function

  80. hi def link goTodo Todo

  81. hi def link goLineComment goComment

  82. hi def link goComment Comment

  83. hi def link goNumbers Number

  84. hi def link goNumbersCom Number

  85. hi def link goNumber Number

  86. hi def link goFloat Float

  87. hi def link goOct Number

  88. hi def link goOctZero Number

  89. hi def link goString String

  90. hi def link goSpecial Special

  91. hi def link goCharacter Character

  92. let b:current_Syntax = "go"

猜你在找的程序笔记相关文章