-
Notifications
You must be signed in to change notification settings - Fork 3
/
filetype.vim
111 lines (93 loc) · 4.33 KB
/
filetype.vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
" ============================================================================
" File: filetype.vim
" Author: Faris Chugthai
" Description: Your personal ftdetect
" Last Modified: Oct 10, 2019
" ============================================================================
if exists('b:loaded_filetype_vim') || &compatible || v:version < 700
finish
endif
let b:loaded_filetype_vim = 1
let g:requirements#detect_filename_pattern = 'Pipfile'
let g:is_bash = 1
fun! s:TryDetectJinja()
if exists("b:did_jinja_autodetect")
return
endif
let b:did_jinja_autodetect=1
let n = 1
while n < 50 && n < line("$")
let line = getline(n)
if line =~ '{%\s*\(extends\|block\|macro\|set\|if\|for\|include\|trans\)\>' || line =~ '{{\s*\S+[|(]'
setlocal filetype=htmljinja
return
endif
let n = n + 1
endwhile
endfun
fun! s:ConsiderSwitchingToJinja()
if exists("b:did_jinja_autodetect")
return
endif
let b:did_jinja_autodetect=1
let n = 1
while n < 50 && n < line("$")
let line = getline(n)
" Bail on django specific tags
if line =~ '{%\s*\(load\|autoescape \(on\|off\)\|cycle\|empty\)\>'
return
" Bail on django filter syntax
elseif line =~ '\({%\|{{\).*|[a-zA-Z0-9]\+:'
return
endif
let n = n + 1
endwhile
setlocal filetype=htmljinja
endfun
fun! s:ConsiderSwitchingToJinjaAgain()
unlet b:did_jinja_autodetect
call s:TryDetectJinja()
endfun
function! s:SelectHTML() abort
let l:n = 1
while l:n < 50 && l:n <= line('$')
" check for jinja
if getline(l:n) =~? '{{.*}}\|{%-\?\s*\(end.*\|extends\|block\|macro\|set\|if\|for\|include\|trans\)\>'
setlocal filetype=htmljinja.htmldjango
return
endif
let l:n = l:n + 1
endwhile
endfunction
augroup Userftdetect
au!
au BufNewFile,BufRead *.json,*.jsonp,*.webmanifest,*.code-workspace setfiletype json
au BufNewFile,BufRead *.jupyterlab-settings,*.ipynb,*.code-snippets setfiletype json
au BufNewFile,BufRead .bashrc,bashrc,bash.bashrc,.bash[_-]profile,.bash[_-]logout,.bash[_-]aliases,bash-fc[-.],*.bash,*/{,.}bash[_-]completion{,.d,.sh}{,/*},*.ebuild,*.eclass,PKGBUILD call dist#ft#SetFileTypeSH("bash")
au BufNewFile,BufRead */etc/profile,.profile,*.sh,*.env setfiletype bash
" call dist#ft#SetFileTypeSH(getline(1))
au BufNewFile,BufRead *.sip setfiletype cpp
au BufNewFile,BufRead setup.cfg setfiletype dosini
au BufNewFile,BufRead *.xonshrc,*.xsh setfiletype xonsh
" YESSSS I used bracket expansion correctly fuck yes
au BufNewFile,BufRead *.tmux{,.conf} setfiletype tmux
au BufNewFile,BufRead *.rst.txt setfiletype rst.txt
au BufNewFile,BufRead *.rst_t setfiletype htmljinja.htmldjango
au BufNewFile,BufRead *.html,*.htm,*.nunjucks,*.nunjs,*.njk call s:SelectHTML()
au BufNewFile,BufRead *.jinja2,*.j2,*.jinja,*.tera setfiletype htmljinja.htmldjango
" idk if the filetypes are gonna work the way we want them to but whqtever
au Filetype jinja setfiletype htmljinja.htmldjango
" NOTE: No dot because the file gitconfig should also match
au BufNewFile,BufRead *gitconfig setfiletype gitconfig
au BufNewFile,BufRead *.css_t setfiletype css
au BufNewFile,BufRead *.rktd setfiletype lisp
" Is this correct or was this a typo?
au BufNewFile,BufRead *.rktl setfiletype lisp
" Go dep and Rust use several TOML config files that are not named with .toml.
au BufNewFile,BufRead *.toml,Gopkg.lock,Cargo.lock,*/.cargo/config,*/.cargo/credentials,Pipfile setfiletype toml
au BufNewFile,BufRead requirements*.txt setfiletype config
autocmd FileType htmldjango call s:ConsiderSwitchingToJinja()
autocmd FileType html call s:TryDetectJinja()
autocmd BufWritePost *.html,*.htm,*.shtml,*.stm call s:ConsiderSwitchingToJinjaAgain()
autocmd BufNewFile,BufRead *.info,*.info.gz setfiletype info
augroup END