Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ftdetect/caddyfile.vim
Original file line number Diff line number Diff line change
@@ -1 +1 @@
au BufNewFile,BufRead Caddyfile set ft=caddyfile
au BufNewFile,BufRead Caddyfile,*.Caddyfile,Caddyfile.* set ft=caddyfile
7 changes: 4 additions & 3 deletions ftplugin/caddyfile.vim
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
" Language: Caddyfile
" Author: Josh Glendenning <[email protected]>
" Language: Caddyfile
" Maintainer: 0az <[email protected]>
" Original Author: Josh Glendenning <[email protected]>

if exists('b:did_ftplugin')
finish
Expand All @@ -16,7 +17,7 @@ if exists('g:NERDDelimiterMap')
endif
elseif exists('g:NERDCustomDelimiters')
if !has_key(g:NERDCustomDelimiters, 'caddyfile')
let g:NERDDelimiterMap.caddyfile = s:delimiters
let g:NERDCustomDelimiters.caddyfile = s:delimiters
endif
else
let g:NERDCustomDelimiters = {'caddyfile': s:delimiters}
Expand Down
39 changes: 29 additions & 10 deletions syntax/caddyfile.vim
Original file line number Diff line number Diff line change
@@ -1,29 +1,48 @@
" Language: Caddyfile
" Author: Josh Glendenning <[email protected]>
" Language: Caddyfile
" Maintainer: 0az <[email protected]>
" Original Author: Josh Glendenning <[email protected]>

if exists("b:current_syntax")
finish
endif

syn match caddyDirective "^\s*\([a-zA-Z0-9_]\+\)" nextgroup=caddyDirectiveArgs skipwhite
syn region caddyDirectiveArgs start="" end="\({\|#\|$\)"me=s-1 oneline contained contains=caddyPlaceholder,caddyString nextgroup=caddyDirectiveBlock skipwhite
syn region caddyDirectiveBlock start="{" skip="\\}" end="}" contained contains=caddySubdirective,caddyComment
syn match caddyDirective "\v^\s*(\w\S*)" nextgroup=caddyDirectiveArgs skipwhite
syn region caddyDirectiveArgs start="" end="\({\|#\|$\)"me=s-1 oneline contained contains=caddyPlaceholder,caddyString,caddyNamedMatcher nextgroup=caddyDirectiveBlock skipwhite
syn region caddyDirectiveBlock start="{" skip="\\}" end="}" contained contains=caddySubdirective,caddyComment,caddyImport

syn match caddySubdirective "^\s*\([a-zA-Z0-9_]\+\)" contained nextgroup=caddySubdirectiveArgs skipwhite
syn region caddySubdirectiveArgs start="" end="\(#\|$\)"me=s-1 oneline contained contains=caddyPlaceholder,caddyString
syn match caddySubdirective "\v^\s*(\w\S*)" contained nextgroup=caddySubdirectiveArgs skipwhite
syn region caddySubdirectiveArgs start="" end="\(#\|$\)"me=s-1 oneline contained contains=caddyPlaceholder,caddyString,caddyNamedMatcher

syn match caddyHost "\(https\?:\/\/\)\?\(\(\w\{1,}\.\)\(\w\{2,}\.\?\)\+\|localhost\)\(:[0-9]\{1,5}\)\?" nextgroup=caddyHostBlock skipwhite
syn region caddyHostBlock start="{" skip="\\}" end="}" contained contains=caddyDirective,caddyComment
" Needs priority over Directive
syn match caddyImport "\v^\s*<import>" nextgroup=caddyImportPattern skipwhite
syn match caddyImportPattern "\v\c\S+" contained nextgroup=caddyImportArgs skipwhite
syn region caddyImportArgs start="" end="$"me=s-1 oneline contained contains=caddyPlaceholder,caddyString,caddyNamedMatcher

syn match caddyHost "\v\c^\s*\zs(https?://)?(([0-9a-z-]+\.)([0-9a-z-]+\.?)+|[0-9a-z-]+)?(:\d{1,5})?" nextgroup=caddyHostBlock skipwhite
syn region caddyHostBlock start="{" skip="\\}" end="}" contained contains=caddyDirective,caddyComment,caddyNamedMatcherDef,caddyImport

" Needs priority over Host
syn region caddySnippetDef start="("rs=e+1 end=")"re=s-1 oneline keepend contains=caddySnippet
syn match caddySnippet "\v\w+" contained nextgroup=caddySnippetBlock skipwhite

syn match caddyNamedMatcher "\v^\s*\zs\@\S+" contained skipwhite
syn match caddyNamedMatcherDef "\v\s*\zs\@\S+" nextgroup=caddyNamedMatcherDefBlock
syn region caddyNamedMatcherDefBlock start="{" skip="\\}" end="}" contained contains=caddySubdirective,caddyComment,caddyImport

syn region caddyPlaceholder start="{" skip="\\}" end="}" oneline contained
syn region caddyString start='"' skip='\\\\\|\\"' end='"' oneline
syn match caddyComment "#.*$"
syn region caddyComment start="#" end="$" oneline

hi link caddyDirective Keyword
hi link caddySubdirective Structure
hi link caddyHost Identifier
hi link caddyImport PreProc
hi link caddySnippetDef PreProc
hi link caddySnippet Identifier
hi link caddyPlaceholder Special
hi link caddyString String
hi link caddyComment Comment
hi link caddyNamedMatcherDef caddyNamedMatcher
hi link caddyNamedMatcher Identifier

let b:current_syntax = "caddyfile"