blob: bce6772762d9a568db0171cdb09c8b23ffcbf70c [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
Tim Popefda02d02023-12-28 12:48:27 -05005" Last Change: 2023 Dec 28
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
Tim Popefda02d02023-12-28 12:48:27 -050024if get(g:, 'gitcommit_summary_length') < 0
25 syn match gitcommitSummary "^.*$" contained containedin=gitcommitFirstLine nextgroup=gitcommitOverflow contains=@Spell
26elseif get(g:, 'gitcommit_summary_length', 1) > 0
27 exe 'syn match gitcommitSummary "^.*\%<' . (get(g:, 'gitcommit_summary_length', 50) + 1) . 'v." contained containedin=gitcommitFirstLine nextgroup=gitcommitOverflow contains=@Spell'
28endif
Bram Moolenaar8c8de832008-06-24 22:58:06 +000029syn match gitcommitOverflow ".*" contained contains=@Spell
Bram Moolenaar2f0936c2022-01-08 21:51:59 +000030syn match gitcommitBlank "^.\+" contained contains=@Spell
31syn match gitcommitFirstLine "\%^.*" nextgroup=gitcommitBlank,gitcommitComment skipnl
Bram Moolenaarc08ee742019-12-05 22:47:25 +010032
Bram Moolenaar2f0936c2022-01-08 21:51:59 +000033let s:scissors = 0
34let s:l = search('^[#;@!$%^&|:] -\{24,\} >8 -\{24,\}$', 'cnW', '', 100)
35if s:l == 0
36 let s:l = line('$')
37elseif getline(s:l)[0] !=# getline(s:l - 1)[0]
38 let s:scissors = 1
Bram Moolenaarc08ee742019-12-05 22:47:25 +010039endif
Bram Moolenaar2f0936c2022-01-08 21:51:59 +000040let s:comment = escape((matchstr(getline(s:l), '^[#;@!$%^&|:]\S\@!') . '#')[0], '^$.*[]~\"/')
Bram Moolenaarc08ee742019-12-05 22:47:25 +010041
Bram Moolenaar2f0936c2022-01-08 21:51:59 +000042if s:scissors
43 let s:comment .= ' -\{24,\} >8 -\{24,\}$'
44 exe 'syn region gitcommitComment start="^' . s:comment . '" end="\%$" contains=gitcommitDiff'
45else
46 exe 'syn match gitcommitComment "^' . s:comment . '.*"'
47endif
48exe '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*\%$\)\@="'
49
50unlet s:l s:comment s:scissors
51
52syn match gitcommitTrailerToken "^[[:alnum:]-]\+\s*:" contained containedin=gitcommitTrailers
53
54syn match gitcommitHash "\<\x\{40,}\>" contains=@NoSpell display
55syn match gitcommitOnBranch "\%(^. \)\@<=On branch" contained containedin=gitcommitComment nextgroup=gitcommitBranch skipwhite
56syn match gitcommitOnBranch "\%(^. \)\@<=Your branch .\{-\} '" contained containedin=gitcommitComment nextgroup=gitcommitBranch skipwhite
Bram Moolenaar53bfca22012-04-13 23:04:47 +020057syn match gitcommitBranch "[^ ']\+" contained
Bram Moolenaar2f0936c2022-01-08 21:51:59 +000058syn match gitcommitNoBranch "\%(^. \)\@<=Not currently on any branch." contained containedin=gitcommitComment
59syn match gitcommitHeader "\%(^. \)\@<=\S.*[::]\%(\n^$\)\@!$" contained containedin=gitcommitComment
60syn region gitcommitAuthor matchgroup=gitCommitHeader start=/\%(^. \)\@<=\%(Author\|Committer\|Date\):/ end=/$/ keepend oneline contained containedin=gitcommitComment transparent
61syn match gitcommitHeader "\%(^. \)\@<=commit\%( \x\{40,\}$\)\@=" contained containedin=gitcommitComment nextgroup=gitcommitHash skipwhite
62syn match gitcommitNoChanges "\%(^. \)\@<=No changes$" contained containedin=gitcommitComment
Bram Moolenaar8c8de832008-06-24 22:58:06 +000063
Bram Moolenaar2f0936c2022-01-08 21:51:59 +000064syn match gitcommitType "\%(^.\t\)\@<=[^[:punct:][:space:]][^/::]*[^[:punct:][:space:]][::]\ze "he=e-1 contained containedin=gitcommitComment nextgroup=gitcommitFile skipwhite
65syn match gitcommitFile ".\{-\}\%($\| -> \)\@=" contained nextgroup=gitcommitArrow
66syn match gitcommitArrow " -> " contained nextgroup=gitcommitFile
67syn match gitcommitUntrackedFile "\%(^.\t\)\@<=[^::/]*\%(/.*\)\=$" contained containedin=gitcommitComment
Bram Moolenaar8c8de832008-06-24 22:58:06 +000068
Bram Moolenaar2f0936c2022-01-08 21:51:59 +000069syn region gitcommitUntracked start=/^\z(.\) Untracked files:$/ end=/^\z1\=$\|^\z1\@!/ contains=gitcommitHeader containedin=gitcommitComment containedin=gitcommitComment contained transparent fold
70syn 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
71syn region gitcommitSelected start=/^\z(.\) Changes to be committed:$/ end=/^\z1$\|^\z1\@!/ contains=gitcommitHeader,gitcommitSelectedType containedin=gitcommitComment containedin=gitcommitComment contained transparent fold
72syn 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 +000073
Bram Moolenaar2f0936c2022-01-08 21:51:59 +000074syn match gitcommitUntrackedFile "\%(^.\t\)\@<=.*" contained containedin=gitcommitUntracked
Bram Moolenaar89bcfda2016-08-30 23:26:57 +020075
Bram Moolenaar2f0936c2022-01-08 21:51:59 +000076syn match gitcommitDiscardedType "\%(^.\t\)\@<=[^[:punct:][:space:]][^/::]*[^[:punct:][:space:]][::]\ze "he=e-1 contained nextgroup=gitcommitDiscardedFile skipwhite
77syn match gitcommitSelectedType "\%(^.\t\)\@<=[^[:punct:][:space:]][^/::]*[^[:punct:][:space:]][::]\ze "he=e-1 contained nextgroup=gitcommitSelectedFile skipwhite
78syn match gitcommitUnmergedType "\%(^.\t\)\@<=[^[:punct:][:space:]][^/::]*[^[:punct:][:space:]][::]\ze "he=e-1 contained nextgroup=gitcommitUnmergedFile skipwhite
79syn match gitcommitDiscardedFile "\S.\{-\}\%($\| -> \)\@=" contained nextgroup=gitcommitDiscardedArrow
80syn match gitcommitSelectedFile "\S.\{-\}\%($\| -> \)\@=" contained nextgroup=gitcommitSelectedArrow
81syn match gitcommitUnmergedFile "\S.\{-\}\%($\| -> \)\@=" contained nextgroup=gitcommitUnmergedArrow
Bram Moolenaar8c8de832008-06-24 22:58:06 +000082syn match gitcommitDiscardedArrow " -> " contained nextgroup=gitcommitDiscardedFile
83syn match gitcommitSelectedArrow " -> " contained nextgroup=gitcommitSelectedFile
Bram Moolenaar2f0936c2022-01-08 21:51:59 +000084syn match gitcommitUnmergedArrow " -> " contained nextgroup=gitcommitUnmergedFile
Bram Moolenaar8c8de832008-06-24 22:58:06 +000085
86hi def link gitcommitSummary Keyword
Bram Moolenaar2f0936c2022-01-08 21:51:59 +000087hi def link gitcommitTrailerToken Label
Bram Moolenaar8c8de832008-06-24 22:58:06 +000088hi def link gitcommitComment Comment
Bram Moolenaar2f0936c2022-01-08 21:51:59 +000089hi def link gitcommitHash Identifier
Bram Moolenaar8c8de832008-06-24 22:58:06 +000090hi def link gitcommitOnBranch Comment
91hi def link gitcommitBranch Special
Bram Moolenaar5c736222010-01-06 20:54:52 +010092hi def link gitcommitNoBranch gitCommitBranch
Bram Moolenaar8c8de832008-06-24 22:58:06 +000093hi def link gitcommitDiscardedType gitcommitType
94hi def link gitcommitSelectedType gitcommitType
Bram Moolenaar5c736222010-01-06 20:54:52 +010095hi def link gitcommitUnmergedType gitcommitType
Bram Moolenaar8c8de832008-06-24 22:58:06 +000096hi def link gitcommitType Type
Bram Moolenaar5c736222010-01-06 20:54:52 +010097hi def link gitcommitNoChanges gitcommitHeader
Bram Moolenaar8c8de832008-06-24 22:58:06 +000098hi def link gitcommitHeader PreProc
99hi def link gitcommitUntrackedFile gitcommitFile
100hi def link gitcommitDiscardedFile gitcommitFile
101hi def link gitcommitSelectedFile gitcommitFile
Bram Moolenaar5c736222010-01-06 20:54:52 +0100102hi def link gitcommitUnmergedFile gitcommitFile
Bram Moolenaar8c8de832008-06-24 22:58:06 +0000103hi def link gitcommitFile Constant
104hi def link gitcommitDiscardedArrow gitcommitArrow
105hi def link gitcommitSelectedArrow gitcommitArrow
Bram Moolenaar5c736222010-01-06 20:54:52 +0100106hi def link gitcommitUnmergedArrow gitcommitArrow
Bram Moolenaar8c8de832008-06-24 22:58:06 +0000107hi def link gitcommitArrow gitcommitComment
108"hi def link gitcommitOverflow Error
109hi def link gitcommitBlank Error
110
111let b:current_syntax = "gitcommit"