vim

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

handlebars.vim (7388B)


      1 " Vim syntax file
      2 " Language:     Handlebars
      3 " Maintainer:   Devin Weaver
      4 " Last Change:  2026 Feb 20
      5 " Origin:       https://github.com/joukevandermaas/vim-ember-hbs
      6 " Credits:      Jouke van der Maas
      7 " License:      MIT
      8 " The MIT License (MIT)
      9 "
     10 " Copyright (c) 2026 Devin Weaver
     11 " Copyright (c) 2015 Jouke van der Maas
     12 "
     13 " Permission is hereby granted, free of charge, to any person obtaining a copy
     14 " of this software and associated documentation files (the "Software"), to deal
     15 " in the Software without restriction, including without limitation the rights
     16 " to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
     17 " copies of the Software, and to permit persons to whom the Software is
     18 " furnished to do so, subject to the following conditions:
     19 "
     20 " The above copyright notice and this permission notice shall be included in all
     21 " copies or substantial portions of the Software.
     22 "
     23 " THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     24 " IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     25 " FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
     26 " AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     27 " LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
     28 " OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
     29 " SOFTWARE.
     30 
     31 if exists("b:current_syntax")
     32   finish
     33 endif
     34 
     35 runtime! syntax/html.vim
     36 syntax cluster htmlPreproc add=hbsComponent,hbsMustache,hbsUnescaped,hbsMustacheBlock,hbsComment,hbsElseBlock,hbsEscapedMustache
     37 
     38 syntax match hbsEscapedMustache "\v\\\{\{"
     39 
     40 syntax region hbsComponent matchgroup=hbsComponentStatement start="\v\<\/?:?\a+(\.\a+|::-?\a+)*" end="\v\/?\>" keepend
     41 syntax region hbsMustache matchgroup=hbsHandles start="\v\{\{" skip="\v\\\}\}" end="\v\}\}" containedin=hbsComponent,hbsString keepend
     42 syntax region hbsMustacheBlock matchgroup=hbsHandles start="\v\{\{[#/]" skip="\v\\\}\}" end="\v\}\}" keepend
     43 " modern hbs supports {{else <block>}} where <block> starts a new block
     44 syntax region hbsElseBlock matchgroup=hbsHandles start="\v\{\{else\ "rs=e-5 skip="\v\\\}\}" end="\v\}\}" keepend
     45 
     46 syntax region hbsPencil matchgroup=hbsOperator start="\v\(" end="\v\)" contained containedin=hbsMustache,hbsMustacheBlock,hbsElseBlock,hbsPencil
     47 
     48 " identifier is any word inside a mustache or a pencil that is not followed by a = sign (see hbsArg below)
     49 syntax match hbsIdentifier "\v(\(|\{\{[#/]?)@<!<(\w+)|(\@\w+)>" contained containedin=hbsMustache,hbsMustacheBlock,hbsPencil,hbsElseBlock,hbsStatement
     50 
     51 " unescaped are special forms of mustaches that don't have other stuff except for an identifier in it
     52 syntax region hbsUnescaped matchgroup=hbsUnescapedHandles start="\v\{\{\{" skip="\v\\\}\}\}" end="\v\}\}\}" keepend
     53 syntax match hbsUnescapedIdentifier "\v(\{\{\{)@<=<\S+>(\}\}\})" contained containedin=hbsUnescaped
     54 
     55 syntax match hbsMustacheName "\v(\{\{[#/]?)@<=<\S+>" contained containedin=hbsMustache,hbsMustacheBlock,hbsPencil
     56 syntax match hbsPencilName "\v(\()@<=<\S+>" contained containedin=hbsMustache,hbsMustacheBlock,hbsPencil
     57 syntax match hbsBuiltInHelper "\v\(@<=<(query-params|mut|fn|array|hash|get|action|unbound|concat)>" contained containedin=hbsPencil
     58 syntax match hbsBuiltInHelper "\v(\{\{)@<=<(textarea|mut|fn|array|hash|input|get|action|on|input|unbound)>" contained containedin=hbsMustache
     59 syntax match hbsBuiltInHelper "\v(\{\{[#/]?)@<=<(component|with|link\-to)>" contained containedin=hbsMustacheBlock,hbsElseBlock
     60 syntax match hbsBuiltInHelperInElse "\v(\{\{else\ )@<=<(component|link\-to)>" contained containedin=hbsMustacheBlock,hbsElseBlock
     61 syntax match hbsControlFlow "\v(\{\{)@<=<else>( ?)@=" contained containedin=hbsElseBlock
     62 syntax match hbsControlFlow "\v\(@<=<(if|unless)>" contained containedin=hbsPencil
     63 syntax match hbsControlFlow "\v(\{\{)@<=<(debugger|unless|yield|outlet|else)>" contained containedin=hbsMustache
     64 syntax match hbsControlFlow "\v(\{\{[#/]?)@<=<(with|let|if|each(\-in)?|unless)>" contained containedin=hbsMustacheBlock,hbsElseBlock
     65 syntax match hbsKeyword "\v\s+as\s+" contained containedin=hbsComponent,hbsMustacheBlock,hbsElseBlock
     66 syntax region hbsStatement matchgroup=hbsDelimiter start="\v\|" end="\v\|" contained containedin=hbsComponent,hbsMustacheBlock,hbsElseBlock
     67 
     68 syntax region hbsString matchgroup=hbsString start=/\v\"/ skip=/\v\\\"/ end=/\v\"/ extend contained containedin=hbsComponent,hbsMustache,hbsMustacheBlock,hbsPencil,hbsElseBlock
     69 syntax region hbsString matchgroup=hbsString start=/\v\'/ skip=/\v\\\'/ end=/\v\'/ extend contained containedin=hbsComponent,hbsMustache,hbsMustacheBlock,hbsPencil,hbsElseBlock
     70 syntax match hbsNumber "\v<\d+>" contained containedin=hbsComponent,hbsMustache,hbsMustacheBlock,hbsPencil,hbsElseBlock
     71 syntax match hbsBool "\v<(true|false)>" contained containedin=hbsComponent,hbsMustache,hbsMustacheBlock,hbsPencil,hbsElseBlock
     72 syntax match hbsArg "\v(\@\S+|\S+)\=@=" contained containedin=hbsComponent,hbsMustache,hbsMustacheBlock,hbsPencil,hbsElseBlock
     73 syntax match hbsOperator "\v(\S+)@<=\=" contained containedin=hbsComponent,hbsMustache,hbsMustacheBlock,hbsPencil,hbsElseBlock
     74 
     75 syntax region hbsComment start="\v\{\{\!" end="\v\}\}" keepend
     76 syntax region hbsComment start="\v\{\{\!\-\-" end="\v\-\-\}\}" keepend
     77 
     78 " *Comment	any comment
     79 
     80 " *Constant	any constant
     81 "  String		a string constant: "this is a string"
     82 "  Character	a character constant: 'c', '\n'
     83 "  Number		a number constant: 234, 0xff
     84 "  Boolean	a boolean constant: TRUE, false
     85 "  Float		a floating point constant: 2.3e10
     86 
     87 " *Identifier	any variable name
     88 "  Function	function name (also: methods for classes)
     89 
     90 " *Statement	any statement
     91 "  Conditional	if, then, else, endif, switch, etc.
     92 "  Repeat		for, do, while, etc.
     93 "  Label		case, default, etc.
     94 "  Operator	"sizeof", "+", "*", etc.
     95 "  Keyword	any other keyword
     96 "  Exception	try, catch, throw
     97 
     98 " *PreProc	generic Preprocessor
     99 "  Include	preprocessor #include
    100 "  Define		preprocessor #define
    101 "  Macro		same as Define
    102 "  PreCondit	preprocessor #if, #else, #endif, etc.
    103 
    104 " *Type		int, long, char, etc.
    105 "  StorageClass	static, register, volatile, etc.
    106 "  Structure	struct, union, enum, etc.
    107 "  Typedef	A typedef
    108 
    109 " *Special	any special symbol
    110 "  SpecialChar	special character in a constant
    111 "  Tag		you can use CTRL-] on this
    112 "  Delimiter	character that needs attention
    113 "  SpecialComment	special things inside a comment
    114 "  Debug		debugging statements
    115 
    116 " *Underlined	text that stands out, HTML links
    117 
    118 " *Ignore		left blank, hidden  |hl-Ignore|
    119 
    120 " *Error		any erroneous construct
    121 
    122 " *Todo		anything that needs extra attention; mostly the
    123 " 		keywords TODO FIXME and XXX
    124 
    125 highlight link hbsBuiltInHelper Function
    126 highlight link hbsBuiltInHelperInElse Function
    127 highlight link hbsControlFlow Function
    128 highlight link hbsKeyword Keyword
    129 highlight link hbsOperator Operator
    130 highlight link hbsDelimiter Delimiter
    131 highlight link hbsMustacheName Statement
    132 highlight link hbsPencilName Statement
    133 highlight link hbsIdentifier Identifier
    134 highlight link hbsString String
    135 highlight link hbsNumber Special
    136 highlight link hbsBool Boolean
    137 highlight link hbsHandles Define
    138 highlight link hbsComponentStatement Define
    139 highlight link hbsUnescapedHandles Identifier
    140 highlight link hbsUnescapedIdentifier Identifier
    141 highlight link hbsComment Comment
    142 highlight link hbsArg Type
    143 
    144 let b:current_syntax = "handlebars"