vim

Fork of vim, an acceptable text editor
git clone git://git.laack.co/vim.git
Log | Files | Refs | README | LICENSE

graphql.vim (3951B)


      1 " Vim syntax file
      2 " Language:	graphql
      3 " Maintainer:	Jon Parise <jon@indelible.org>
      4 " Filenames:	*.graphql *.graphqls *.gql
      5 " URL:		https://github.com/jparise/vim-graphql
      6 " License:	MIT <https://opensource.org/license/mit>
      7 " Last Change:	2026 Apr 21
      8 
      9 if !exists('main_syntax')
     10   if exists('b:current_syntax')
     11     finish
     12   endif
     13   let main_syntax = 'graphql'
     14 endif
     15 
     16 syn case match
     17 
     18 syn match graphqlComment    "#.*$" contains=@Spell
     19 
     20 syn match graphqlOperator   "=" display
     21 syn match graphqlOperator   "!" display
     22 syn match graphqlOperator   "|" display
     23 syn match graphqlOperator   "&" display
     24 syn match graphqlOperator   "\M..." display
     25 
     26 syn keyword graphqlBoolean  true false
     27 syn keyword graphqlNull     null
     28 syn match   graphqlNumber   "-\=\<\%(0\|[1-9]\d*\)\%(\.\d\+\)\=\%([eE][-+]\=\d\+\)\=\>" display
     29 syn region  graphqlString   start=+"+  skip=+\\\\\|\\"+  end=+"\|$+  contains=graphqlEscape
     30 syn region  graphqlString   start=+"""+ skip=+\\"""+ end=+"""+  contains=graphqlEscape
     31 
     32 syn match   graphqlEscape   +\\["\\/bfnrt]+ contained display
     33 syn match   graphqlEscape   +\\u\x\{4}+     contained display
     34 syn match   graphqlEscape   +\\u{\x\+}+     contained display
     35 syn match   graphqlEscape   +\\""\"+        contained display
     36 
     37 syn keyword graphqlKeyword repeatable nextgroup=graphqlKeyword skipwhite
     38 syn keyword graphqlKeyword on nextgroup=graphqlType,graphqlDirectiveLocation skipwhite
     39 
     40 syn keyword graphqlStructure enum scalar type union nextgroup=graphqlType skipwhite
     41 syn keyword graphqlStructure input interface subscription nextgroup=graphqlType skipwhite
     42 syn keyword graphqlStructure implements nextgroup=graphqlType skipwhite
     43 syn keyword graphqlStructure query mutation fragment nextgroup=graphqlName skipwhite
     44 syn keyword graphqlStructure directive nextgroup=graphqlDirective skipwhite
     45 syn keyword graphqlStructure extend nextgroup=graphqlStructure skipwhite
     46 syn keyword graphqlStructure schema nextgroup=graphqlFold skipwhite
     47 
     48 syn match graphqlDirective  "\<@\h\w*\>"   display
     49 syn match graphqlVariable   "\<\$\h\w*\>"  display
     50 syn match graphqlName       "\<\h\w*\>"    display
     51 syn match graphqlType       "\<_*\u\w*\>"  display
     52 
     53 " https://spec.graphql.org/September2025/#ExecutableDirectiveLocation
     54 syn keyword graphqlDirectiveLocation QUERY MUTATION SUBSCRIPTION FIELD
     55 syn keyword graphqlDirectiveLocation FRAGMENT_DEFINITION FRAGMENT_SPREAD
     56 syn keyword graphqlDirectiveLocation INLINE_FRAGMENT VARIABLE_DEFINITION
     57 " https://spec.graphql.org/September2025/#TypeSystemDirectiveLocation
     58 syn keyword graphqlDirectiveLocation SCHEMA SCALAR OBJECT FIELD_DEFINITION
     59 syn keyword graphqlDirectiveLocation ARGUMENT_DEFINITION INTERFACE UNION
     60 syn keyword graphqlDirectiveLocation ENUM ENUM_VALUE INPUT_OBJECT
     61 syn keyword graphqlDirectiveLocation INPUT_FIELD_DEFINITION
     62 
     63 syn keyword graphqlMetaFields __schema __type __typename
     64 
     65 syn region  graphqlFold matchgroup=graphqlBraces start="{" end="}" transparent fold contains=ALLBUT,graphqlStructure
     66 syn region  graphqlList matchgroup=graphqlBraces start="\[" end="]" transparent contains=ALLBUT,graphqlDirective,graphqlStructure
     67 
     68 if main_syntax ==# 'graphql'
     69   syn sync minlines=500
     70 endif
     71 
     72 hi def link graphqlComment          Comment
     73 hi def link graphqlOperator         Operator
     74 
     75 hi def link graphqlBraces           Delimiter
     76 
     77 hi def link graphqlBoolean          Boolean
     78 hi def link graphqlNull             Keyword
     79 hi def link graphqlNumber           Number
     80 hi def link graphqlString           String
     81 hi def link graphqlEscape           Special
     82 
     83 hi def link graphqlDirective        PreProc
     84 hi def link graphqlDirectiveLocation Special
     85 hi def link graphqlName             Identifier
     86 hi def link graphqlMetaFields       Special
     87 hi def link graphqlKeyword          Keyword
     88 hi def link graphqlStructure        Structure
     89 hi def link graphqlType             Type
     90 hi def link graphqlVariable         Identifier
     91 
     92 let b:current_syntax = 'graphql'
     93 
     94 if main_syntax ==# 'graphql'
     95   unlet main_syntax
     96 endif