Skip to content
Browse files

Version 1.0: Initial upload

  • Loading branch information...
0 parents commit 3e82fec3a60bde0c56b53d34387b1e23b761f845 @lepture lepture committed with
Showing with 263 additions and 0 deletions.
  1. +51 −0 README
  2. +49 −0 README.md
  3. +1 −0 ftdetect/jinja.vim
  4. +77 −0 indent/jinja.vim
  5. +85 −0 syntax/jinja.vim
51 README
@@ -0,0 +1,51 @@
+This is a mirror of http://www.vim.org/scripts/script.php?script_id=4213
+
+# Jinja for Vim
+
+Jinja bundle for vim.
+
+
+## Feature
+
+1. full syntax support
+2. great indent support
+
+## Installation
+
+### Install with [Vundle](https://github.com/gmarik/vundle)
+
+If you are not using vundle, you really should have a try.
+Edit your vimrc:
+
+ Bundle "lepture/vim-jinja"
+
+And install it:
+
+ :so ~/.vimrc
+ :BundleInstall
+
+
+### Install with [pathogen](https://github.com/tpope/vim-pathogen)
+
+If you prefer tpope's pathogen, that's ok. Just clone it:
+
+ cd ~/.vim/bundle
+ git clone https://github.com/lepture/vim-jinja.git
+
+
+## Configuration
+
+No configuration is needed, if you are using vim 7.2+, it will detect if
+a html file is a jinja template.
+
+But if you want to ensure it works well, you can edit your vimrc:
+
+```vim
+au BufNewFile,BufRead *.html,*.htm,*.shtml,*.stm set ft=jinja
+```
+
+
+## Bug report
+
+Report a bug on [GitHub Issues](https://github.com/lepture/vim-jinja/issues).
+
49 README.md
@@ -0,0 +1,49 @@
+# Jinja for Vim
+
+Jinja bundle for vim.
+
+
+## Feature
+
+1. full syntax support
+2. great indent support
+
+## Installation
+
+### Install with [Vundle](https://github.com/gmarik/vundle)
+
+If you are not using vundle, you really should have a try.
+Edit your vimrc:
+
+ Bundle "lepture/vim-jinja"
+
+And install it:
+
+ :so ~/.vimrc
+ :BundleInstall
+
+
+### Install with [pathogen](https://github.com/tpope/vim-pathogen)
+
+If you prefer tpope's pathogen, that's ok. Just clone it:
+
+ cd ~/.vim/bundle
+ git clone https://github.com/lepture/vim-jinja.git
+
+
+## Configuration
+
+No configuration is needed, if you are using vim 7.2+, it will detect if
+a html file is a jinja template.
+
+But if you want to ensure it works well, you can edit your vimrc:
+
+```vim
+au BufNewFile,BufRead *.html,*.htm,*.shtml,*.stm set ft=jinja
+```
+
+
+## Bug report
+
+Report a bug on [GitHub Issues](https://github.com/lepture/vim-jinja/issues).
+
1 ftdetect/jinja.vim
@@ -0,0 +1 @@
+au BufNewFile,BufRead *.html,*.htm,*.shtml,*.stm if &ft == 'htmldjango' | set ft=jinja | endif
77 indent/jinja.vim
@@ -0,0 +1,77 @@
+" jinja indent file
+" Language: Jinja HTML template
+" Maintainer: Hsiaoming Yang <lepture@me.com>
+" Last Change: Sep 13, 2012
+
+" based on django indent by Steve Losh
+
+if exists("b:did_indent")
+ finish
+endif
+
+runtime! indent/html.vim
+unlet! b:did_indent
+
+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=GetJinjaIndent()
+setlocal indentkeys=o,O,*<Return>,{,},o,O,!^F,<>>
+
+" Only define the function once.
+if exists("*GetJinjaIndent")
+ finish
+endif
+
+function! GetJinjaIndent(...)
+ 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\|filter\|macro\|raw\|call\)'
+ let midtags = '\(elif\|else\)'
+
+ 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
85 syntax/jinja.vim
@@ -0,0 +1,85 @@
+" jinja syntax file
+" Language: Jinja HTML template
+" Maintainer: Hsiaoming Yang <lepture@me.com>
+" Last Change: Sep 13, 2012
+
+" only support 6.x+
+
+if exists("b:current_syntax")
+ finish
+endif
+
+if !exists("main_syntax")
+ let main_syntax = 'html'
+endif
+
+runtime! syntax/html.vim
+unlet b:current_syntax
+
+syntax case match
+
+" jinja template built-in tags and parameters
+" 'comment' doesn't appear here because it gets special treatment
+syn keyword jinjaStatement contained if else elif endif is not
+syn keyword jinjaStatement contained for in recursive endfor
+syn keyword jinjaStatement contained raw endraw
+syn keyword jinjaStatement contained block endblock extends super scoped
+syn keyword jinjaStatement contained macro endmacro call endcall
+syn keyword jinjaStatement contained from import as do continue break
+syn keyword jinjaStatement contained filter endfilter set
+syn keyword jinjaStatement contained include ignore missing
+syn keyword jinjaStatement contained with without context endwith
+syn keyword jinjaStatement contained trans endtrans pluralize
+syn keyword jinjaStatement contained autoescape endautoescape
+
+" jinja templete built-in filters
+syn keyword jinjaFilter contained abs attr batch capitalize center default
+syn keyword jinjaFilter contained dictsort escape filesizeformat first
+syn keyword jinjaFilter contained float forceescape format groupby indent
+syn keyword jinjaFilter contained int join last length list lower pprint
+syn keyword jinjaFilter contained random replace reverse round safe slice
+syn keyword jinjaFilter contained sort string striptags sum
+syn keyword jinjaFilter contained title trim truncate upper urlize
+syn keyword jinjaFilter contained wordcount wordwrap
+
+" jinja template built-in tests
+syn keyword jinjaTest contained callable defined divisibleby escaped
+syn keyword jinjaTest contained even iterable lower mapping none number
+syn keyword jinjaTest contained odd sameas sequence string undefined upper
+
+syn keyword jinjaFunction contained range lipsum dict cycler joiner
+
+
+" Keywords to highlight within comments
+syn keyword jinjaTodo contained TODO FIXME XXX
+
+" jinja template constants (always surrounded by double quotes)
+syn region jinjaArgument contained start=/"/ skip=/\\"/ end=/"/
+syn keyword jinjaArgument contained true false
+
+" Mark illegal characters within tag and variables blocks
+syn match jinjaTagError contained "#}\|{{\|[^%]}}\|[&#]"
+syn match jinjaVarError contained "#}\|{%\|%}\|[<>!&#%]"
+syn cluster jinjaBlocks add=jinjaTagBlock,jinjaVarBlock,jinjaComBlock,jinjaComment
+
+" jinja template tag and variable blocks
+syn region jinjaTagBlock start="{%" end="%}" contains=jinjaStatement,jinjaFilter,jinjaArgument,jinjaFilter,jinjaTest,jinjaTagError display containedin=ALLBUT,@jinjaBlocks
+syn region jinjaVarBlock start="{{" end="}}" contains=jinjaFilter,jinjaArgument,jinjaVarError display containedin=ALLBUT,@jinjaBlocks
+syn region jinjaComBlock start="{#" end="#}" contains=jinjaTodo containedin=ALLBUT,@jinjaBlocks
+
+
+hi def link jinjaTagBlock PreProc
+hi def link jinjaVarBlock PreProc
+hi def link jinjaStatement Statement
+hi def link jinjaFunction Function
+hi def link jinjaTest Type
+hi def link jinjaFilter Identifier
+hi def link jinjaArgument Constant
+hi def link jinjaTagError Error
+hi def link jinjaVarError Error
+hi def link jinjaError Error
+hi def link jinjaComment Comment
+hi def link jinjaComBlock Comment
+hi def link jinjaTodo Todo
+
+let b:current_syntax = "jinja"

0 comments on commit 3e82fec

Please sign in to comment.
Something went wrong with that request. Please try again.