VIM 自动加载Tags脚本

 1 function! s:CheckAndAddTagFile(path)
 2     if stridx(a:path, '/') == (strlen(a:path) - 1)
 3         let l:tags = a:path . 'tags'
 4     else
 5         let l:tags = a:path . '/tags'
 6     endif
 7 
 8     if stridx(&tags, l:tags) != -1
 9         echo l:tags "already added"
10         return
11     endif
12 
13     if !filereadable(l:tags)
14         echo l:tags "not readable"
15         return
16     endif
17 
18     let &tags =  len(&tags) == 0 ? l:tags : &tags . ',' . l:tags
19     echo l:tags "added"
20 
21     unlet! l:tags
22 endfunction
23 
24 function! s:StrEndWith(str, pattern)
25     if strridx(a:str, a:pattern) == strlen(a:str) - strlen(a:pattern)
26         return 1
27     else
28         return 0
29     endif
30 endfunction
31 
32 function! s:SplitPath(path)
33     let l:start = 0
34     let l:list = []
35 
36     while 1 == 1
37         let l:idx = stridx(a:path, '/', l:start)
38         let l:start = l:idx + 1
39 
40         if l:idx == -1
41             break
42         endif
43 
44         let l:part = a:path[0:(l:idx > 0 ? l:idx - 1 : l:idx)]
45         call add(l:list, l:part)
46     endwhile
47 
48     if !s:StrEndWith(a:path, '/')
49         call add(l:list, a:path)
50     endif
51 
52     return l:list
53 endfunction
54 
55 function! AddTagsInCwdPath()
56     let l:cwd = tr(expand('%:p:h'), '\', '/')
57 
58     let l:pathes = s:SplitPath(l:cwd)
59 
60     for p in l:pathes
61         call s:CheckAndAddTagFile(p)
62     endfor
63 
64 endfunction
65 
66 " call AddTagsInCwdPath()

 1. 保存为load_tags.vim, 放到vim/plugin目录下

 2. 打开文件之后 :call AddTagsInCwdPath()会将文件所在的目录下以及父目录下的所有tags自动添加到tags配置

 3. TODO: 通过autocmd在打开文件时自动调用AddTagsInCwdPath()

转载于:https://www.cnblogs.com/ellusak/archive/2012/04/18/2455657.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值