vim

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

bazelrc.vim (3813B)


      1 " Vim syntax file
      2 " Language:	Bazel rc file
      3 " Maintainer:	Barrett Ruth <br@barrettruth.com>
      4 " Last Change:	2026 Aug 25
      5 " Reference:	https://bazel.build/run/bazelrc
      6 
      7 " quit when a syntax file was already loaded
      8 if exists("b:current_syntax")
      9   finish
     10 endif
     11 let s:cpo_save = &cpo
     12 set cpo&vim
     13 
     14 syn case match
     15 syn iskeyword @,48-57,_,-
     16 
     17 " Comments {{{1
     18 
     19 " Backslash-newline is removed from the whole file before it is split into
     20 " lines, so a comment ending in one continues into the line below it.
     21 syn region  bazelrcComment
     22       \ start=/#/
     23       \ skip=/\\$/
     24       \ end=/$/
     25       \ contains=bazelrcTodo,@Spell
     26 syn keyword bazelrcTodo	contained TODO FIXME XXX NOTE
     27 
     28 " Words {{{1
     29 
     30 " Bazel joins a continued line onto the one above before splitting the file
     31 " into lines, so what follows is a further option rather than a new command.
     32 syn match   bazelrcContinuation /\\$/
     33       \ skipnl
     34       \ nextgroup=bazelrcContinued
     35 syn match   bazelrcContinued  contained  transparent  /.*/
     36       \ contains=bazelrcComment,bazelrcContinuation,bazelrcEscape,
     37       \	         bazelrcFlag,bazelrcString
     38 
     39 " A backslash escape is absorbed before quoting is considered, so it applies
     40 " inside single quotes too, and '\#' is a literal '#' rather than a comment.
     41 syn match   bazelrcEscape	/\\./
     42 " A quote may open part-way through a word.  An unterminated one is ignored
     43 " rather than continued onto the line below.
     44 syn region  bazelrcString  oneline
     45       \ start=/'/
     46       \ skip=/\\./
     47       \ end=/'/
     48       \ contains=bazelrcEscape
     49 syn region  bazelrcString  oneline
     50       \ start=/"/
     51       \ skip=/\\./
     52       \ end=/"/
     53       \ contains=bazelrcEscape
     54 
     55 " Imports {{{1
     56 
     57 syn match   bazelrcImport	/^\s*try-import-if-bazel-version\>/
     58       \ skipwhite
     59       \ nextgroup=bazelrcVersion
     60 syn match   bazelrcImport	/^\s*\%(try-\)\=import\>/
     61       \ skipwhite
     62       \ nextgroup=bazelrcPath
     63 " The comparison and the version it applies to are a single word.
     64 syn match   bazelrcVersion  contained
     65       \ /\%(<=\|>=\|==\|!=\|[<>~]\)[^ \t#]\+/
     66       \ skipwhite
     67       \ nextgroup=bazelrcPath
     68 syn match   bazelrcPath  contained
     69       \ /\%(\\.\|[^ \t#]\)\+/
     70       \ contains=bazelrcEscape,bazelrcString,bazelrcWorkspace
     71 " Substituted only as a prefix, and the trailing slash belongs to it.
     72 syn match   bazelrcWorkspace  contained /\%(^\|\s\)\@1<=%workspace%\//
     73 
     74 " Commands and options {{{1
     75 
     76 syn match   bazelrcCommand
     77       \ /^\s*\<\%(always\|aquery\|build\|canonicalize-flags\|clean\|common
     78       \\|config\|coverage\|cquery\|dump\|fetch\|help\|info\|license
     79       \\|mobile-install\|mod\|print_action\|query\|run\|shutdown\|startup
     80       \\|test\|vendor\|version\)\>/
     81       \ nextgroup=bazelrcConfig
     82 " A command is split on its first colon, so a config name may contain colons.
     83 syn match   bazelrcConfig  contained /:[^ \t#]\+/
     84 
     85 syn match   bazelrcFlag		/--[^ \t#=]*/	nextgroup=bazelrcValue
     86 syn match   bazelrcFlag		/\%(^\|\s\)\@1<=-[a-zA-Z]\>/
     87       \ nextgroup=bazelrcValue
     88 syn region  bazelrcValue  contained  oneline
     89       \ matchgroup=bazelrcOperator
     90       \ start=/=/
     91       \ end=/\ze[ \t#]/
     92       \ end=/$/
     93       \ contains=bazelrcString,bazelrcEscape
     94 
     95 " Syncing {{{1
     96 
     97 " A comment may continue onto the following line.
     98 syn sync linebreaks=1
     99 
    100 " Default Highlighting {{{1
    101 
    102 hi def link bazelrcComment	Comment
    103 hi def link bazelrcTodo		Todo
    104 hi def link bazelrcContinuation	Special
    105 hi def link bazelrcEscape	SpecialChar
    106 hi def link bazelrcString	String
    107 hi def link bazelrcImport	Include
    108 hi def link bazelrcVersion	Constant
    109 hi def link bazelrcPath		String
    110 hi def link bazelrcWorkspace	PreProc
    111 hi def link bazelrcCommand	Statement
    112 hi def link bazelrcConfig	Type
    113 hi def link bazelrcFlag		Identifier
    114 hi def link bazelrcOperator	Operator
    115 
    116 " }}}
    117 
    118 let b:current_syntax = "bazelrc"
    119 
    120 let &cpo = s:cpo_save
    121 unlet s:cpo_save
    122 
    123 " vim: ts=8 fdm=marker: