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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" 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 |
Exactly what I was looking for. Thanks for sharing this!
Boa Fabio! Obrigado pelo snippet.
Que bom que ajudou!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.