├── LICENSE ├── README.md ├── ftdetect └── caddyfile.vim ├── ftplugin └── caddyfile.vim ├── indent └── caddyfile.vim └── syntax └── caddyfile.vim /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016 Josh Glendenning 2 | 3 | MIT License 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # vim-caddyfile 2 | 3 | Vim support for [Caddy's](https://caddyserver.com/) [Caddyfile](https://caddyserver.com/docs/caddyfile). 4 | 5 | Includes syntax, indentation, and comment support, without depending on a static list of directives. 6 | 7 | ## Installation 8 | ### VimPlug 9 | Put `Plug 'isobit/vim-caddyfile'` in your vimrc and do `:PlugInstall`. 10 | ### Vundle 11 | Put `Bundle 'isobit/vim-caddyfile'` in your vimrc and do `:BundleInstall`. 12 | 13 | ## Preview 14 | ![preview](https://raw.githubusercontent.com/isobit/vim-caddyfile/images/caddyfile-preview.png) 15 | -------------------------------------------------------------------------------- /ftdetect/caddyfile.vim: -------------------------------------------------------------------------------- 1 | au BufNewFile,BufRead Caddyfile,*.Caddyfile,Caddyfile.* set ft=caddyfile 2 | -------------------------------------------------------------------------------- /ftplugin/caddyfile.vim: -------------------------------------------------------------------------------- 1 | " Language: Caddyfile 2 | " Maintainer: 0az <0az@afzhou.com> 3 | " Original Author: Josh Glendenning 4 | 5 | if exists('b:did_ftplugin') 6 | finish 7 | endif 8 | let b:did_ftplugin = 1 9 | 10 | setlocal commentstring=#\ %s 11 | 12 | " Add NERDCommenter delimiters 13 | let s:delimiters = {'left': '#'} 14 | if exists('g:NERDDelimiterMap') 15 | if !has_key(g:NERDDelimiterMap, 'caddyfile') 16 | let g:NERDDelimiterMap.caddyfile = s:delimiters 17 | endif 18 | elseif exists('g:NERDCustomDelimiters') 19 | if !has_key(g:NERDCustomDelimiters, 'caddyfile') 20 | let g:NERDCustomDelimiters.caddyfile = s:delimiters 21 | endif 22 | else 23 | let g:NERDCustomDelimiters = {'caddyfile': s:delimiters} 24 | endif 25 | unlet s:delimiters 26 | -------------------------------------------------------------------------------- /indent/caddyfile.vim: -------------------------------------------------------------------------------- 1 | if exists('b:did_indent') 2 | finish 3 | endif 4 | let b:did_indent = 1 5 | 6 | setlocal nolisp 7 | setlocal autoindent 8 | setlocal indentexpr=GetCaddyfileIndent(v:lnum) 9 | setlocal indentkeys+=<:>,0=},0=) 10 | 11 | if exists('*shiftwidth') 12 | function! s:sw() 13 | return shiftwidth() 14 | endfunc 15 | else 16 | function! s:sw() 17 | return &sw 18 | endfunc 19 | endif 20 | 21 | function! GetCaddyfileIndent(lnum) 22 | let prevlnum = prevnonblank(a:lnum-1) 23 | if prevlnum == 0 24 | return 0 25 | endif 26 | 27 | let thisl = substitute(getline(a:lnum), '#.*$', '', '') 28 | let prevl = substitute(getline(prevlnum), '#.*$', '', '') 29 | 30 | let ind = indent(prevlnum) 31 | 32 | if prevl =~ '{\s*$' 33 | let ind += s:sw() 34 | endif 35 | 36 | if thisl =~ '^\s*}\s*$' 37 | let ind -= s:sw() 38 | endif 39 | 40 | return ind 41 | endfunction 42 | -------------------------------------------------------------------------------- /syntax/caddyfile.vim: -------------------------------------------------------------------------------- 1 | " Language: Caddyfile 2 | " Maintainer: 0az <0az@afzhou.com> 3 | " Original Author: Josh Glendenning 4 | 5 | if exists("b:current_syntax") 6 | finish 7 | endif 8 | 9 | syn match caddyDirective "\v^\s*(\w\S*)" nextgroup=caddyDirectiveArgs skipwhite 10 | syn region caddyDirectiveArgs start="" end="\({\|#\|$\)"me=s-1 oneline contained contains=caddyPlaceholder,caddyString,caddyNamedMatcher nextgroup=caddyDirectiveBlock skipwhite 11 | syn region caddyDirectiveBlock start="{" skip="\\}" end="}" contained contains=caddySubdirective,caddyComment,caddyImport 12 | 13 | syn match caddySubdirective "\v^\s*(\w\S*)" contained nextgroup=caddySubdirectiveArgs skipwhite 14 | syn region caddySubdirectiveArgs start="" end="\(#\|$\)"me=s-1 oneline contained contains=caddyPlaceholder,caddyString,caddyNamedMatcher 15 | 16 | " Needs priority over Directive 17 | syn match caddyImport "\v^\s*" nextgroup=caddyImportPattern skipwhite 18 | syn match caddyImportPattern "\v\c\S+" contained nextgroup=caddyImportArgs skipwhite 19 | syn region caddyImportArgs start="" end="$"me=s-1 oneline contained contains=caddyPlaceholder,caddyString,caddyNamedMatcher 20 | 21 | syn match caddyHost "\v\c^\s*\zs(https?://)?(([0-9a-z-]+\.)([0-9a-z-]+\.?)+|[0-9a-z-]+)?(:\d{1,5})?" nextgroup=caddyHostBlock skipwhite 22 | syn region caddyHostBlock start="{" skip="\\}" end="}" contained contains=caddyDirective,caddyComment,caddyNamedMatcherDef,caddyImport 23 | 24 | " Needs priority over Host 25 | syn region caddySnippetDef start="("rs=e+1 end=")"re=s-1 oneline keepend contains=caddySnippet 26 | syn match caddySnippet "\v\w+" contained nextgroup=caddySnippetBlock skipwhite 27 | 28 | syn match caddyNamedMatcher "\v^\s*\zs\@\S+" contained skipwhite 29 | syn match caddyNamedMatcherDef "\v\s*\zs\@\S+" nextgroup=caddyNamedMatcherDefBlock 30 | syn region caddyNamedMatcherDefBlock start="{" skip="\\}" end="}" contained contains=caddySubdirective,caddyComment,caddyImport 31 | 32 | syn region caddyPlaceholder start="{" skip="\\}" end="}" oneline contained 33 | syn region caddyString start='"' skip='\\\\\|\\"' end='"' oneline 34 | syn region caddyComment start="#" end="$" oneline 35 | 36 | hi link caddyDirective Keyword 37 | hi link caddySubdirective Structure 38 | hi link caddyHost Identifier 39 | hi link caddyImport PreProc 40 | hi link caddySnippetDef PreProc 41 | hi link caddySnippet Identifier 42 | hi link caddyPlaceholder Special 43 | hi link caddyString String 44 | hi link caddyComment Comment 45 | hi link caddyNamedMatcherDef caddyNamedMatcher 46 | hi link caddyNamedMatcher Identifier 47 | 48 | let b:current_syntax = "caddyfile" 49 | --------------------------------------------------------------------------------