beancount.vim (4459B)
1 " Vim syntax file 2 " Language: beancount 3 " Maintainer: Nathan Grigg 4 " Latest Revision: 2024-11-25 5 " 2026 Jun 22 by Vim Project: allow non-ASCII account names 6 7 if exists("b:current_syntax") 8 finish 9 endif 10 11 syntax clear 12 " Basics. 13 syn region beanComment start="\s*;" end="$" keepend contains=beanMarker 14 syn match beanMarker "\v(\{\{\{|\}\}\})\d?" contained 15 syn region beanString start='"' skip='\\"' end='"' contained 16 syn match beanAmount "\v[-+]?[[:digit:].,]+" nextgroup=beanCurrency contained 17 \ skipwhite 18 syn match beanCurrency "\v\w+" contained 19 " Account name: alphanumeric with at least one colon. 20 syn match beanAccount "\v[[:alnum:]]+:\S+" contained 21 syn match beanTag "\v#[-[:alnum:]]+" contained 22 syn match beanLink "\v\^\S+" contained 23 " We must require a space after the flag because you can have flags per 24 " transaction leg, and the letter-based flags might get confused with the 25 " start of an account name. 26 syn match beanFlag "\v[*!&#?%PSTCURM]\s\@=" contained 27 28 " Most directives start with a date. 29 syn match beanDate "^\v\d{4}[-/]\d{2}[-/]\d{2}" skipwhite 30 \ nextgroup=beanOpen,beanTxn,beanClose,beanCommodity,beanNote,beanBalance,beanEvent,beanPad,beanPrice 31 " Options and events have two string arguments. The first, we are matching as 32 " beanOptionTitle and the second as a regular string. 33 syn region beanOption matchgroup=beanKeyword start="^option" end="$" 34 \ keepend contains=beanOptionTitle,beanComment 35 syn region beanOption matchgroup=beanKeyword start="^plugin" end="$" 36 \ keepend contains=beanString,beanComment 37 syn region beanInclude matchgroup=beanKeyword start="^include" end="$" 38 \ keepend contains=beanString,beanComment 39 syn region beanEvent matchgroup=beanKeyword start="event" end="$" contained 40 \ keepend contains=beanOptionTitle,beanComment 41 syn region beanOptionTitle start='"' skip='\\"' end='"' contained 42 \ nextgroup=beanString skipwhite 43 syn region beanOpen matchgroup=beanKeyword start="open" end="$" keepend 44 \ contained contains=beanAccount,beanCurrency,beanComment 45 syn region beanClose matchgroup=beanKeyword start="close" end="$" keepend 46 \ contained contains=beanAccount,beanComment 47 syn region beanCommodity matchgroup=beanKeyword start="commodity" end="$" keepend 48 \ contained contains=beanCurrency,beanComment 49 syn region beanNote matchgroup=beanKeyword start="\vnote|document" end="$" 50 \ keepend contains=beanAccount,beanString,beanComment contained 51 syn region beanBalance matchgroup=beanKeyword start="balance" end="$" contained 52 \ keepend contains=beanAccount,beanAmount,beanComment 53 syn region beanPrice matchgroup=beanKeyword start="price" end="$" contained 54 \ keepend contains=beanCurrency,beanAmount 55 syn region beanPushTag matchgroup=beanKeyword start="\v^(push|pop)tag" end="$" 56 \ keepend contains=beanTag 57 syn region beanPad matchgroup=beanKeyword start="pad" end="$" contained 58 \ keepend contains=beanAccount,beanComment 59 60 syn region beanTxn matchgroup=beanKeyword start="\v\s+(txn|[*!&#?%PSTCURM])" skip="^\s" 61 \ end="^" keepend contained fold 62 \ contains=beanString,beanPost,beanComment,beanTag,beanLink,beanMeta 63 syn region beanPost start="^\v\C\s+(([*!&#?%PSTCURM]\s+)?[A-Z])@=" end="$" 64 \ contains=beanFlag,beanAccount,beanAmount,beanComment,beanCost,beanPrice 65 syn region beanMeta matchgroup=beanTag start="^\v\C\s+[a-z][-_a-zA-Z0-9]*:(\s|$)@=" end="$" 66 67 syn region beanCost start="{" end="}" contains=beanAmount contained 68 syn match beanPrice "\V@@\?" nextgroup=beanAmount contained 69 70 syn region beanHashHeaderFold 71 \ start="^\z(#\+\)" 72 \ skip="^\s*\z1#\+" 73 \ end="^\(#\)\@=" 74 \ fold contains=TOP 75 76 syn region beanStarHeaderFold 77 \ start="^\z(\*\+\)" 78 \ skip="^\s*\z1\*\+" 79 \ end="^\(\*\)\@=" 80 \ fold contains=TOP 81 82 highlight default link beanKeyword Keyword 83 highlight default link beanOptionTitle Keyword 84 highlight default link beanDate Keyword 85 highlight default link beanString String 86 highlight default link beanComment Comment 87 highlight default link beanAccount Identifier 88 highlight default link beanAmount Number 89 highlight default link beanCurrency Number 90 highlight default link beanCost Number 91 highlight default link beanPrice Number 92 highlight default link beanTag Tag 93 highlight default link beanLink Comment 94 highlight default link beanMeta Special 95 highlight default link beanFlag Keyword