-
Notifications
You must be signed in to change notification settings - Fork 14
/
vim-dict.vim
50 lines (40 loc) · 1.35 KB
/
vim-dict.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
" 插件用于自动加载对应文件类型的字典文件
"
" Author: Asins (http://nootn.com)
" Last Modified: 2016-02-23 17:53 (+0800)
" Update Modified: 2019-02-11 10:33 (+0800)
" 可在_vimrc文件中指定伴随字典,如
" let g:vim_dict_config = {
" \ 'html': ['css', 'javascript']
" \ 'javascript': ['jsx'],
" \}
" 插件默认自动对html格式文件关联css javascript两个字典
" <sfile> = vim-dict/autoload 需回到上层目录
let s:dictDirPath = expand('<sfile>:p:h:h?\\?/?').'/dict/'
" 默认配置
let s:defaultConfigMap = {
\ 'html': ['css', 'javascript'],
\}
if exists('g:vim_dict_config')
call extend(g:vim_dict_config, s:defaultConfigMap, 'keep')
else
let g:vim_dict_config = s:defaultConfigMap
endif
function! s:AutoLoadDict(filetype)
let a:dictPath = s:dictDirPath.a:filetype.'.dic'
" 未指定文件类型 || 已加载
if a:filetype == '' || strridx(&dictionary, a:dictPath) >= 0
return
endif
" 字典存在
if findfile(a:dictPath) != ''
" echo 'load fileType:'.a:filetype 'path:'.a:dictPath
silent execute 'setlocal dictionary+='.fnameescape(a:dictPath)
endif
let a:childFileTypeList = get(g:vim_dict_config, a:filetype, [])
" echo 'a:childFileTypeList == ' a:childFileTypeList
for nr in a:childFileTypeList
call s:AutoLoadDict(nr)
endfor
endfunction
autocmd FileType * call s:AutoLoadDict(&filetype)