blob: 42c8d4414f0f0f05a1061113726d5cca1d4218df [file] [log] [blame]
Bram Moolenaar8c8de832008-06-24 22:58:06 +00001" Vim syntax file
2" Language: git commit file
Bram Moolenaar5c736222010-01-06 20:54:52 +01003" Maintainer: Tim Pope <vimNOSPAM@tpope.org>
Bram Moolenaar8c8de832008-06-24 22:58:06 +00004" Filenames: *.git/COMMIT_EDITMSG
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00005" Last Change: 2022 Jan 05
Bram Moolenaar8c8de832008-06-24 22:58:06 +00006
7if exists("b:current_syntax")
Bram Moolenaar7a329912010-05-21 12:05:36 +02008 finish
Bram Moolenaar8c8de832008-06-24 22:58:06 +00009endif
10
Bram Moolenaar2f0936c2022-01-08 21:51:59 +000011scriptencoding utf-8
12
Bram Moolenaar8c8de832008-06-24 22:58:06 +000013syn case match
14syn sync minlines=50
Bram Moolenaar2f0936c2022-01-08 21:51:59 +000015syn sync linebreaks=1
Bram Moolenaar8c8de832008-06-24 22:58:06 +000016
17if has("spell")
Bram Moolenaar7a329912010-05-21 12:05:36 +020018 syn spell toplevel
Bram Moolenaar8c8de832008-06-24 22:58:06 +000019endif
20
21syn include @gitcommitDiff syntax/diff.vim
Bram Moolenaar2f0936c2022-01-08 21:51:59 +000022syn region gitcommitDiff start=/\%(^diff --\%(git\|cc\|combined\) \)\@=/ end=/^\%(diff --\|$\|@@\@!\|[^[:alnum:]\ +-]\S\@!\)\@=/ fold contains=@gitcommitDiff
Bram Moolenaar8c8de832008-06-24 22:58:06 +000023
Bram Moolenaarc08ee742019-12-05 22:47:25 +010024syn match gitcommitSummary "^.*\%<51v." contained containedin=gitcommitFirstLine nextgroup=gitcommitOverflow contains=@Spell
Bram Moolenaar8c8de832008-06-24 22:58:06 +000025syn match gitcommitOverflow ".*" contained contains=@Spell
Bram Moolenaar2f0936c2022-01-08 21:51:59 +000026syn match gitcommitBlank "^.\+" contained contains=@Spell
27syn match gitcommitFirstLine "\%^.*" nextgroup=gitcommitBlank,gitcommitComment skipnl
Bram Moolenaarc08ee742019-12-05 22:47:25 +010028
Bram Moolenaar2f0936c2022-01-08 21:51:59 +000029let s:scissors = 0
30let s:l = search('^[#;@!$%^&|:] -\{24,\} >8 -\{24,\}$', 'cnW', '', 100)
31if s:l == 0
32 let s:l = line('$')
33elseif getline(s:l)[0] !=# getline(s:l - 1)[0]
34 let s:scissors = 1
Bram Moolenaarc08ee742019-12-05 22:47:25 +010035endif
Bram Moolenaar2f0936c2022-01-08 21:51:59 +000036let s:comment = escape((matchstr(getline(s:l), '^[#;@!$%^&|:]\S\@!') . '#')[0], '^$.*[]~\"/')
Bram Moolenaarc08ee742019-12-05 22:47:25 +010037
Bram Moolenaar2f0936c2022-01-08 21:51:59 +000038if s:scissors
39 let s:comment .= ' -\{24,\} >8 -\{24,\}$'
40 exe 'syn region gitcommitComment start="^' . s:comment . '" end="\%$" contains=gitcommitDiff'
41else
42 exe 'syn match gitcommitComment "^' . s:comment . '.*"'
43endif
44exe 'syn match gitcommitTrailers "\n\@<=\n\%([[:alnum:]-]\+\s*:.*\|(cherry picked from commit .*\)\%(\n\s.*\|\n[[:alnum:]-]\+\s*:.*\|\n(cherry picked from commit .*\)*\%(\n\n*\%(' . s:comment . '\)\|\n*\%$\)\@="'
45
46unlet s:l s:comment s:scissors
47
48syn match gitcommitTrailerToken "^[[:alnum:]-]\+\s*:" contained containedin=gitcommitTrailers
49
50syn match gitcommitHash "\<\x\{40,}\>" contains=@NoSpell display
51syn match gitcommitOnBranch "\%(^. \)\@<=On branch" contained containedin=gitcommitComment nextgroup=gitcommitBranch skipwhite
52syn match gitcommitOnBranch "\%(^. \)\@<=Your branch .\{-\} '" contained containedin=gitcommitComment nextgroup=gitcommitBranch skipwhite
Bram Moolenaar53bfca22012-04-13 23:04:47 +020053syn match gitcommitBranch "[^ ']\+" contained
Bram Moolenaar2f0936c2022-01-08 21:51:59 +000054syn match gitcommitNoBranch "\%(^. \)\@<=Not currently on any branch." contained containedin=gitcommitComment
55syn match gitcommitHeader "\%(^. \)\@<=\S.*[::]\%(\n^$\)\@!$" contained containedin=gitcommitComment
56syn region gitcommitAuthor matchgroup=gitCommitHeader start=/\%(^. \)\@<=\%(Author\|Committer\|Date\):/ end=/$/ keepend oneline contained containedin=gitcommitComment transparent
57syn match gitcommitHeader "\%(^. \)\@<=commit\%( \x\{40,\}$\)\@=" contained containedin=gitcommitComment nextgroup=gitcommitHash skipwhite
58syn match gitcommitNoChanges "\%(^. \)\@<=No changes$" contained containedin=gitcommitComment
Bram Moolenaar8c8de832008-06-24 22:58:06 +000059
Bram Moolenaar2f0936c2022-01-08 21:51:59 +000060syn match gitcommitType "\%(^.\t\)\@<=[^[:punct:][:space:]][^/::]*[^[:punct:][:space:]][::]\ze "he=e-1 contained containedin=gitcommitComment nextgroup=gitcommitFile skipwhite
61syn match gitcommitFile ".\{-\}\%($\| -> \)\@=" contained nextgroup=gitcommitArrow
62syn match gitcommitArrow " -> " contained nextgroup=gitcommitFile
63syn match gitcommitUntrackedFile "\%(^.\t\)\@<=[^::/]*\%(/.*\)\=$" contained containedin=gitcommitComment
Bram Moolenaar8c8de832008-06-24 22:58:06 +000064
Bram Moolenaar2f0936c2022-01-08 21:51:59 +000065syn region gitcommitUntracked start=/^\z(.\) Untracked files:$/ end=/^\z1\=$\|^\z1\@!/ contains=gitcommitHeader containedin=gitcommitComment containedin=gitcommitComment contained transparent fold
66syn region gitcommitDiscarded start=/^\z(.\) Change\%(s not staged for commit\|d but not updated\):$/ end=/^\z1\=$\|^\z1\@!/ contains=gitcommitHeader,gitcommitDiscardedType containedin=gitcommitComment containedin=gitcommitComment contained transparent fold
67syn region gitcommitSelected start=/^\z(.\) Changes to be committed:$/ end=/^\z1$\|^\z1\@!/ contains=gitcommitHeader,gitcommitSelectedType containedin=gitcommitComment containedin=gitcommitComment contained transparent fold
68syn region gitcommitUnmerged start=/^\z(.\) Unmerged paths:$/ end=/^\z1\=$\|^\z1\@!/ contains=gitcommitHeader,gitcommitUnmergedType containedin=gitcommitComment containedin=gitcommitComment contained transparent fold
Bram Moolenaar8c8de832008-06-24 22:58:06 +000069
Bram Moolenaar2f0936c2022-01-08 21:51:59 +000070syn match gitcommitUntrackedFile "\%(^.\t\)\@<=.*" contained containedin=gitcommitUntracked
Bram Moolenaar89bcfda2016-08-30 23:26:57 +020071
Bram Moolenaar2f0936c2022-01-08 21:51:59 +000072syn match gitcommitDiscardedType "\%(^.\t\)\@<=[^[:punct:][:space:]][^/::]*[^[:punct:][:space:]][::]\ze "he=e-1 contained nextgroup=gitcommitDiscardedFile skipwhite
73syn match gitcommitSelectedType "\%(^.\t\)\@<=[^[:punct:][:space:]][^/::]*[^[:punct:][:space:]][::]\ze "he=e-1 contained nextgroup=gitcommitSelectedFile skipwhite
74syn match gitcommitUnmergedType "\%(^.\t\)\@<=[^[:punct:][:space:]][^/::]*[^[:punct:][:space:]][::]\ze "he=e-1 contained nextgroup=gitcommitUnmergedFile skipwhite
75syn match gitcommitDiscardedFile "\S.\{-\}\%($\| -> \)\@=" contained nextgroup=gitcommitDiscardedArrow
76syn match gitcommitSelectedFile "\S.\{-\}\%($\| -> \)\@=" contained nextgroup=gitcommitSelectedArrow
77syn match gitcommitUnmergedFile "\S.\{-\}\%($\| -> \)\@=" contained nextgroup=gitcommitUnmergedArrow
Bram Moolenaar8c8de832008-06-24 22:58:06 +000078syn match gitcommitDiscardedArrow " -> " contained nextgroup=gitcommitDiscardedFile
79syn match gitcommitSelectedArrow " -> " contained nextgroup=gitcommitSelectedFile
Bram Moolenaar2f0936c2022-01-08 21:51:59 +000080syn match gitcommitUnmergedArrow " -> " contained nextgroup=gitcommitUnmergedFile
Bram Moolenaar8c8de832008-06-24 22:58:06 +000081
82hi def link gitcommitSummary Keyword
Bram Moolenaar2f0936c2022-01-08 21:51:59 +000083hi def link gitcommitTrailerToken Label
Bram Moolenaar8c8de832008-06-24 22:58:06 +000084hi def link gitcommitComment Comment
Bram Moolenaar2f0936c2022-01-08 21:51:59 +000085hi def link gitcommitHash Identifier
Bram Moolenaar8c8de832008-06-24 22:58:06 +000086hi def link gitcommitOnBranch Comment
87hi def link gitcommitBranch Special
Bram Moolenaar5c736222010-01-06 20:54:52 +010088hi def link gitcommitNoBranch gitCommitBranch
Bram Moolenaar8c8de832008-06-24 22:58:06 +000089hi def link gitcommitDiscardedType gitcommitType
90hi def link gitcommitSelectedType gitcommitType
Bram Moolenaar5c736222010-01-06 20:54:52 +010091hi def link gitcommitUnmergedType gitcommitType
Bram Moolenaar8c8de832008-06-24 22:58:06 +000092hi def link gitcommitType Type
Bram Moolenaar5c736222010-01-06 20:54:52 +010093hi def link gitcommitNoChanges gitcommitHeader
Bram Moolenaar8c8de832008-06-24 22:58:06 +000094hi def link gitcommitHeader PreProc
95hi def link gitcommitUntrackedFile gitcommitFile
96hi def link gitcommitDiscardedFile gitcommitFile
97hi def link gitcommitSelectedFile gitcommitFile
Bram Moolenaar5c736222010-01-06 20:54:52 +010098hi def link gitcommitUnmergedFile gitcommitFile
Bram Moolenaar8c8de832008-06-24 22:58:06 +000099hi def link gitcommitFile Constant
100hi def link gitcommitDiscardedArrow gitcommitArrow
101hi def link gitcommitSelectedArrow gitcommitArrow
Bram Moolenaar5c736222010-01-06 20:54:52 +0100102hi def link gitcommitUnmergedArrow gitcommitArrow
Bram Moolenaar8c8de832008-06-24 22:58:06 +0000103hi def link gitcommitArrow gitcommitComment
104"hi def link gitcommitOverflow Error
105hi def link gitcommitBlank Error
106
107let b:current_syntax = "gitcommit"