diff --git a/README.md b/README.md index 388384b..13295f2 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ A collection of language packs for Vim. > One to rule them all, one to find them, one to bring them all and in the darkness bind them. - It **won't affect your startup time**, as scripts are loaded only on demand\*. -- It **installs and updates 100+ times faster** than the 119 packages it consists of. +- It **installs and updates 100+ times faster** than the 120 packages it consists of. - Solid syntax and indentation support (other features skipped). Only the best language packs. - All unnecessary files are ignored (like enormous documentation from php support). - No support for esoteric languages, only most popular ones (modern too, like `slim`). @@ -91,6 +91,7 @@ If you need full functionality of any plugin, please use it directly with your p - [jasmine](https://github.com/glanotte/vim-jasmine) (syntax) - [javascript](https://github.com/pangloss/vim-javascript) (syntax, indent, compiler, ftplugin, extras) - [jenkins](https://github.com/martinda/Jenkinsfile-vim-syntax) (syntax, indent) +- [jinja](https://github.com/lepture/vim-jinja) (syntax, indent) - [json5](https://github.com/GutenYe/json5.vim) (syntax) - [json](https://github.com/elzr/vim-json) (syntax, indent, ftplugin) - [jst](https://github.com/briancollins/vim-jst) (syntax, indent) diff --git a/build b/build index 3083686..398a8e5 100755 --- a/build +++ b/build @@ -63,7 +63,7 @@ extract() { output "${subdirs##, })"$'\n' - if (echo "julia coffee-script elixir fish git plantuml scala swift" | grep -qF "$name"); then + if (echo "julia coffee-script elixir fish git plantuml scala swift jinja" | grep -qF "$name"); then echo "Skipping ftdetect installation of $name" >&2 continue fi @@ -199,6 +199,7 @@ PACKS=" jasmine:glanotte/vim-jasmine javascript:pangloss/vim-javascript:_JAVASCRIPT jenkins:martinda/Jenkinsfile-vim-syntax + jinja:lepture/vim-jinja json5:GutenYe/json5.vim json:elzr/vim-json jst:briancollins/vim-jst diff --git a/config.vim b/config.vim index 8a3c128..b48dc5a 100644 --- a/config.vim +++ b/config.vim @@ -67,6 +67,10 @@ augroup filetypedetect " swift autocmd BufNewFile,BufRead *.swift set filetype=swift + + + "jinja + autocmd BufNewFile,BufRead *.jinja2,*.j2,*.jinja,*.nunjucks,*.nunjs,*.njk set ft=jinja augroup END " Fix for https://github.com/sheerun/vim-polyglot/issues/236#issuecomment-387984954 diff --git a/ftdetect/polyglot.vim b/ftdetect/polyglot.vim index c61fa08..ef4d4d0 100644 --- a/ftdetect/polyglot.vim +++ b/ftdetect/polyglot.vim @@ -67,6 +67,10 @@ augroup filetypedetect " swift autocmd BufNewFile,BufRead *.swift set filetype=swift + + + "jinja + autocmd BufNewFile,BufRead *.jinja2,*.j2,*.jinja,*.nunjucks,*.nunjs,*.njk set ft=jinja augroup END " Fix for https://github.com/sheerun/vim-polyglot/issues/236#issuecomment-387984954 diff --git a/indent/jinja.vim b/indent/jinja.vim new file mode 100644 index 0000000..759d3ee --- /dev/null +++ b/indent/jinja.vim @@ -0,0 +1,84 @@ +if exists('g:polyglot_disabled') && index(g:polyglot_disabled, 'jinja') != -1 + finish +endif + +" Vim indent file +" Language: Jinja HTML template +" Maintainer: Evan Hammer +" Last Change: 2013 Jan 26 + +" Only load this indent file when no other was loaded. +if exists("b:did_indent") + finish +endif + +" Use HTML formatting rules. +setl indentkeys=o,O,,<>>,!^F +runtime! indent/html.vim +setl nosmartindent +let b:did_indent = 1 + +" Indent within the jinja tags +" Made by Steve Losh +if &l:indentexpr == '' + if &l:cindent + let &l:indentexpr = 'cindent(v:lnum)' + else + let &l:indentexpr = 'indent(prevnonblank(v:lnum-1))' + endif +endif +let b:html_indentexpr = &l:indentexpr + +let b:did_indent = 1 + +setlocal indentexpr=GetDjangoIndent() +setlocal indentkeys=o,O,*,{,},o,O,!^F,<>> + +" Only define the function once. +if exists("*GetDjangoIndent") + finish +endif + +function! GetDjangoIndent(...) + if a:0 && a:1 == '.' + let v:lnum = line('.') + elseif a:0 && a:1 =~ '^\d' + let v:lnum = a:1 + endif + let vcol = col('.') + + call cursor(v:lnum,vcol) + + exe "let ind = ".b:html_indentexpr + + let lnum = prevnonblank(v:lnum-1) + let pnb = getline(lnum) + let cur = getline(v:lnum) + + let tagstart = '.*' . '{%\s*' + let tagend = '.*%}' . '.*' + + let blocktags = '\(block\|for\|if\|with\|autoescape\|comment\|filter\|spaceless\)' + let midtags = '\(empty\|else\|elif\)' + + let pnb_blockstart = pnb =~# tagstart . blocktags . tagend + let pnb_blockend = pnb =~# tagstart . 'end' . blocktags . tagend + let pnb_blockmid = pnb =~# tagstart . midtags . tagend + + let cur_blockstart = cur =~# tagstart . blocktags . tagend + let cur_blockend = cur =~# tagstart . 'end' . blocktags . tagend + let cur_blockmid = cur =~# tagstart . midtags . tagend + + if pnb_blockstart && !pnb_blockend + let ind = ind + &sw + elseif pnb_blockmid && !pnb_blockend + let ind = ind + &sw + endif + + if cur_blockend && !cur_blockstart + let ind = ind - &sw + elseif cur_blockmid + let ind = ind - &sw + endif + + return ind +endfunction diff --git a/syntax/html.vim b/syntax/html.vim index a050361..a529b56 100644 --- a/syntax/html.vim +++ b/syntax/html.vim @@ -192,3 +192,97 @@ syn keyword htmlArg contained scriptlevel scriptminsize scriptsize scriptsizemul syn keyword htmlArg contained stretchy subscriptshift superscriptshift symmetric thickmathspace thinmathspace type valign verythickmathspace verythinmathspace syn keyword htmlArg contained veryverythickmathspace veryverythinmathspace voffset width xref +if exists('g:polyglot_disabled') && index(g:polyglot_disabled, 'jinja') != -1 + finish +endif + +" Vim syntax file +" Language: HTML (version 5) +" Maintainer: Rodrigo Machado +" URL: http://rm.blog.br/vim/syntax/html.vim +" Last Change: 2009 Aug 19 +" License: Public domain +" (but let me know if you like :) ) +" +" Note: This file just adds the new tags from HTML 5 +" and don't replace default html.vim syntax file +" +" Modified: othree +" Changes: update to Draft 28 August 2010 +" add complete new attributes +" add wai-aria attributes +" add microdata attributes +" add rdfa attributes + + +syn keyword htmlTagName contained script +" HTML 5 tags +syn keyword htmlTagName contained article aside audio canvas command +syn keyword htmlTagName contained datalist details dialog embed figcaption figure footer +syn keyword htmlTagName contained header hgroup keygen mark meter menu nav output +syn keyword htmlTagName contained progress time ruby rt rp section source summary time track video wbr + +" HTML 5 arguments +" Core Attributes +syn keyword htmlArg contained accesskey class contenteditable contextmenu dir +syn keyword htmlArg contained draggable hidden id lang spellcheck style tabindex title +" Event-handler Attributes +syn keyword htmlArg contained onabort onblur oncanplay oncanplaythrough onchange +syn keyword htmlArg contained onclick oncontextmenu ondblclick ondrag ondragend ondragenter ondragleave ondragover +syn keyword htmlArg contained ondragstart ondrop ondurationchange onemptied onended onerror onfocus onformchange +syn keyword htmlArg contained onforminput oninput oninvalid onkeydown onkeypress onkeyup onload onloadeddata +syn keyword htmlArg contained onloadedmetadata onloadstart onmousedown onmousemove onmouseout onmouseover onmouseup +syn keyword htmlArg contained onmousewheel onpause onplay onplaying onprogress onratechange onreadystatechange +syn keyword htmlArg contained onscroll onseeked onseeking onselect onshow onstalled onsubmit onsuspend ontimeupdate +syn keyword htmlArg contained onvolumechange onwaiting +" XML Attributes +syn keyword htmlArg contained xml:lang xml:space xml:base +" new features +" +syn keyword htmlArg contained onafterprint onbeforeprint onbeforeunload onblur onerror onfocus onhashchange onload +syn keyword htmlArg contained onmessage onoffline ononline onpopstate onredo onresize onstorage onundo onunload +"