my configs
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

324 lines
7.7 KiB

  1. " Override system filetype.vim
  2. if exists('g:did_load_filetypes')
  3. finish
  4. endif
  5. let g:did_load_filetypes = 1
  6. " If we don't have +autocmd or are 'compatible', do nothing, and don't try
  7. " again later
  8. if !has('autocmd') || &compatible
  9. finish
  10. endif
  11. " Helper function to run the 'filetypedetect' group on a file with its
  12. " extension stripped off
  13. function! s:StripRepeat()
  14. " Check we have the fnameescape() function
  15. if !exists('*fnameescape')
  16. return
  17. endif
  18. " Expand the match result
  19. let l:fn = expand('<afile>')
  20. " Strip leading and trailing #hashes#
  21. if l:fn =~# '^#\+.*#\+$'
  22. let l:fn = substitute(l:fn, '^#\+\(.\+\)#\+$', '\1', '')
  23. " Strip trailing tilde~
  24. elseif l:fn =~# '\~$'
  25. let l:fn = substitute(l:fn, '\~$', '', '')
  26. " Strip generic .extension
  27. else
  28. let l:fn = expand('<afile>:r')
  29. endif
  30. " Re-run the group if there's anything left
  31. if strlen(l:fn)
  32. execute 'doautocmd filetypedetect BufRead ' . fnameescape(l:fn)
  33. endif
  34. endfunction
  35. " Check whether the first line was changed and looks like a shebang, and if
  36. " so, re-run filetype detection
  37. function! s:CheckShebang()
  38. if line('''[') == 1 && getline(1) =~# '^#!'
  39. doautocmd filetypedetect BufRead
  40. endif
  41. endfunction
  42. " Use our own filetype detection rules
  43. augroup filetypedetect
  44. autocmd!
  45. " Unwrap hashes, tildes, generic extensions, and Debian packaging working
  46. " extensions (if we can do so safely), and repeat the filetype detection to
  47. " see if there's a match beneath them
  48. autocmd BufNewFile,BufRead
  49. \ #?*#
  50. \,?*~
  51. \,?*.{bak,example,in,new,old,orig,sample,test}
  52. \,?*.dpkg-{bak,dist,new,old}
  53. \ call s:StripRepeat()
  54. " CSS files
  55. autocmd BufNewFile,BufRead
  56. \ ?*.css
  57. \ setfiletype css
  58. " CSV files
  59. autocmd BufNewFile,BufRead
  60. \ ?*.csv
  61. \ setfiletype csv
  62. " Diff and patch files
  63. autocmd BufNewFile,BufRead
  64. \ ?*.diff
  65. \,?*.patch
  66. \,?*.rej
  67. \ setfiletype diff
  68. " INI files
  69. autocmd BufNewFile,BufRead
  70. \ ?*.ini
  71. \ setfiletype dosini
  72. " DOT graphs
  73. autocmd BufNewFile,BufRead
  74. \ ?*.dot
  75. \ setfiletype dot
  76. " Forth
  77. autocmd BufNewFile,BufRead
  78. \ ?*.fs,?*.ft
  79. \ setfiletype forth
  80. " fstab(5) files
  81. autocmd BufNewFile,BufRead
  82. \ fstab
  83. \ setfiletype fstab
  84. " GDB init files
  85. autocmd BufNewFile,BufRead
  86. \ .gdbinit
  87. \ setfiletype gdb
  88. " GnuPG configuration files
  89. autocmd BufNewFile,BufRead
  90. \ *gnupg/options
  91. \,*gnupg/gpg.conf
  92. \ setfiletype gpg
  93. " UNIX group file
  94. autocmd BufNewFile,BufRead
  95. \ /etc/group
  96. \,/etc/group-
  97. \,/etc/group.edit
  98. \,/etc/gshadow
  99. \,/etc/gshadow-
  100. \,/etc/gshadow.edit
  101. \ setfiletype group
  102. " GTK settings files
  103. autocmd BufNewFile,BufRead
  104. \ .gktrc*,
  105. \,gktrc*
  106. \ setfiletype gtkrc
  107. " inittab(5) files
  108. autocmd BufNewFile,BufRead
  109. \ inittab
  110. \ setfiletype inittab
  111. " Java files
  112. autocmd BufNewFile,BufRead
  113. \ ?*.java
  114. \,?*.jav
  115. \ setfiletype java
  116. " JSON files
  117. autocmd BufNewFile,BufRead
  118. \ ?*.json
  119. \ setfiletype json
  120. " Lex files
  121. autocmd BufNewFile,BufRead
  122. \ ?*.l
  123. \,?*.lex
  124. \ setfiletype lex
  125. " Lua files
  126. autocmd BufNewFile,BufRead
  127. \ ?*.lua
  128. \ setfiletype lua
  129. " m4 files
  130. autocmd BufNewFile,BufRead
  131. \ ?*.m4
  132. \ setfiletype m4
  133. " Makefiles
  134. autocmd BufNewFile,BufRead
  135. \ Makefile
  136. \,makefile
  137. \ setfiletype make
  138. " Markdown files
  139. autocmd BufNewFile,BufRead
  140. \ ?*.markdown
  141. \,?*.md
  142. \ setfiletype markdown
  143. " Mutt configuration files
  144. autocmd BufNewFile,BufRead
  145. \ Muttrc
  146. \,*/.muttrc.d/*.rc
  147. \,.muttrc
  148. \,/etc/Muttrc.d/*
  149. \ setfiletype muttrc
  150. " Nano configuration file
  151. autocmd BufNewFile,BufRead
  152. \ *.nanorc
  153. \,*/etc/nanorc
  154. \ setfiletype nanorc
  155. " netrc file
  156. autocmd BufNewFile,BufRead
  157. \ .netrc
  158. \,netrc
  159. \ setfiletype netrc
  160. " roff files
  161. autocmd BufNewFile,BufRead
  162. \ ?*.roff
  163. \,?*.[1-9]
  164. \,*/man[1-9]*/?*.[1-9]*
  165. \ setfiletype nroff
  166. " UNIX password and shadow files
  167. autocmd BufNewFile,BufRead
  168. \ /etc/passwd
  169. \,/etc/passwd-
  170. \,/etc/passwd.edit
  171. \,/etc/shadow
  172. \,/etc/shadow-
  173. \,/etc/shadow.edit
  174. \ setfiletype passwd
  175. " pass(1) password files
  176. autocmd BufNewFile,BufRead
  177. \ /dev/shm/pass.?*/?*.txt
  178. \,$TMPDIR/pass.?*/?*.txt
  179. \,/tmp/pass.?*/?*.txt
  180. \ setfiletype password
  181. " Python files
  182. autocmd BufNewFile,BufRead
  183. \ ?*.py
  184. \ setfiletype python
  185. " Readline configuration file
  186. autocmd BufNewFile,BufRead
  187. \ .inputrc
  188. \,inputrc
  189. \ setfiletype readline
  190. " Remind files
  191. autocmd BufNewFile,BufRead
  192. \ .reminders
  193. \,?*.rem
  194. \,?*.remind
  195. \ setfiletype remind
  196. " robots.txt files
  197. autocmd BufNewFile,BufRead
  198. \ robots.txt
  199. \ setfiletype robots
  200. " Ruby
  201. autocmd BufNewFile,BufRead
  202. \ ?*.rb
  203. \,Puppetfile
  204. \ setfiletype ruby
  205. " sed files
  206. autocmd BufNewFile,BufRead
  207. \ ?*.sed
  208. \ setfiletype sed
  209. " Services files
  210. autocmd BufNewFile,BufRead
  211. \ /etc/services
  212. \ setfiletype services
  213. " sudoers(5)
  214. autocmd BufNewFile,BufRead
  215. \ sudoers
  216. \,sudoers.tmp
  217. \ setfiletype sudoers
  218. " Subversion commit
  219. autocmd BufNewFile,BufRead
  220. \ svn-commit*.tmp
  221. \ setfiletype svn
  222. " Systemd unit files
  223. autocmd BufNewFile,BufRead
  224. \ */systemd/*.*
  225. \ setfiletype systemd
  226. " TCL
  227. autocmd BufNewFile,BufRead
  228. \ ?*.tcl
  229. \ setfiletype tcl
  230. " Terminfo
  231. autocmd BufNewFile,BufRead
  232. \ ?*.ti
  233. \ setf terminfo
  234. " Tidy config
  235. autocmd BufNewFile,BufRead
  236. \ .tidyrc
  237. \,tidyrc
  238. \ setfiletype tidy
  239. " tmux configuration files
  240. autocmd BufNewFile,BufRead
  241. \ .tmux.conf
  242. \,tmux.conf
  243. \ setfiletype tmux
  244. " Tab-separated (TSV) files
  245. autocmd BufNewFile,BufRead
  246. \ ?*.tsv
  247. \ setfiletype tsv
  248. " .wgetrc files
  249. autocmd BufNewFile,BufRead
  250. \ .wgetrc
  251. \,wgetrc
  252. \ setfiletype wget
  253. " XML files
  254. autocmd BufNewFile,BufRead
  255. \ ?*.xml
  256. \ setfiletype xml
  257. " Yacc files
  258. autocmd BufNewFile,BufRead
  259. \ ?*.y
  260. \,?*.yy
  261. \ setfiletype yacc
  262. " Load any extra rules in ftdetect directories
  263. runtime! ftdetect/*.vim
  264. " Generic text, config, and log files, if no type assigned yet
  265. autocmd BufNewFile,BufRead
  266. \ ?*.text
  267. \,?*.txt
  268. \,INSTALL
  269. \,README
  270. \,/etc/issue
  271. \,/etc/motd
  272. \ setfiletype text
  273. autocmd BufNewFile,BufRead
  274. \ ?*.cfg
  275. \,?*.conf
  276. \,?*.config
  277. \,/etc/*
  278. \ setfiletype config
  279. autocmd BufNewFile,BufRead
  280. \ */log/*
  281. \,?*.log
  282. \ setfiletype messages
  283. " Clumsy attempt at typing files in `sudo -e` if a filename hasn't already
  284. " been found; strip temporary extension and re-run
  285. autocmd BufNewFile,BufRead
  286. \ /var/tmp/?*.????????
  287. \ if !did_filetype()
  288. \| call s:StripRepeat()
  289. \|endif
  290. " If we still don't have a filetype, run the scripts.vim file that performs
  291. " cleverer checks including looking at actual file contents--but only my
  292. " custom one; don't load the system one at all.
  293. autocmd BufNewFile,BufRead,StdinReadPost
  294. \ *
  295. \ if !did_filetype()
  296. \| lua require'scripts'
  297. \|endif
  298. " If supported, on leaving insert mode, check whether the first line was
  299. " changed and looks like a shebang format, and if so, re-run filetype
  300. " detection
  301. if v:version > 700
  302. autocmd InsertLeave * call s:CheckShebang()
  303. endif
  304. augroup END