Skip to content

Instantly share code, notes, and snippets.

@fabiomcosta
Created June 19, 2012 22:42
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save fabiomcosta/2956964 to your computer and use it in GitHub Desktop.
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
Copy link
Author

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
Copy link

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

@niloct
Copy link

niloct commented Aug 9, 2019

Boa Fabio! Obrigado pelo snippet.

@fabiomcosta
Copy link
Author

Que bom que ajudou!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment