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 |
This comment has been minimized.
This comment has been minimized.
Exactly what I was looking for. Thanks for sharing this! |
This comment has been minimized.
This comment has been minimized.
Boa Fabio! Obrigado pelo snippet. |
This comment has been minimized.
This comment has been minimized.
Que bom que ajudou! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
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.