Skip to content

Instantly share code, notes, and snippets.

@fabiomcosta fabiomcosta/.vimrc
Created Jun 19, 2012

Embed
What would you like to do?
Better filetype detection for djangohtml on .html files on VIM. The default one just checks for the existence of `{%\s*\(extends\|block\)` on the first 10 lines, and sometimes, on include files for example, you dont have any of them. Thi
" a better htmldjango detection
augroup filetypedetect
" removes current htmldjango detection located at $VIMRUNTIME/filetype.vim
au! BufNewFile,BufRead *.html
au BufNewFile,BufRead *.html call FThtml()
func! FThtml()
let n = 1
while n < 10 && n < line("$")
if getline(n) =~ '\<DTD\s\+XHTML\s'
setf xhtml
return
endif
if getline(n) =~ '{%\|{{\|{#'
setf htmldjango
return
endif
let n = n + 1
endwhile
setf html
endfunc
augroup END
@fabiomcosta

This comment has been minimized.

Copy link
Owner Author

commented Jun 19, 2012

Better filetype detection for djangohtml on .html files on VIM. The default one just checks for the existence of {%\s*\(extends\|block\) on the first 10 lines, and sometimes, on include files for example, you dont have any of them.
This new detection checks for any {%|{{|{# on the first 10 lines of the file, which works better.
Just add this to your .vimrc file.

@thebitguru

This comment has been minimized.

Copy link

commented Aug 21, 2013

Exactly what I was looking for. Thanks for sharing this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.