VIM 自动加载Tags脚本
2012-04-18 17:34
447 查看
function! s:CheckAndAddTagFile(path) if stridx(a:path, '/') == (strlen(a:path) - 1) let l:tags = a:path . 'tags' else let l:tags = a:path . '/tags' endif if stridx(&tags, l:tags) != -1 echo l:tags "already added" return endif if !filereadable(l:tags) echo l:tags "not readable" return endif let &tags = len(&tags) == 0 ? l:tags : &tags . ',' . l:tags echo l:tags "added" unlet! l:tags endfunction function! s:StrEndWith(str, pattern) if strridx(a:str, a:pattern) == strlen(a:str) - strlen(a:pattern) return 1 else return 0 endif endfunction function! s:SplitPath(path) let l:start = 0 let l:list = [] while 1 == 1 let l:idx = stridx(a:path, '/', l:start) let l:start = l:idx + 1 if l:idx == -1 break endif let l:part = a:path[0:(l:idx > 0 ? l:idx - 1 : l:idx)] call add(l:list, l:part) endwhile if !s:StrEndWith(a:path, '/') call add(l:list, a:path) endif return l:list endfunction function! AddTagsInCwdPath() let l:cwd = tr(expand('%:p:h'), '\', '/') let l:pathes = s:SplitPath(l:cwd) for p in l:pathes call s:CheckAndAddTagFile(p) endfor endfunction " call AddTagsInCwdPath()
1. 保存为load_tags.vim, 放到vim/plugin目录下
2. 打开文件之后 :call AddTagsInCwdPath()会将文件所在的目录下以及父目录下的所有tags自动添加到tags配置
3. TODO: 通过autocmd在打开文件时自动调用AddTagsInCwdPath()
相关文章推荐
- vim自动加载模板的插件~
- 如何在vim编辑器中使用键盘F4自动添加脚本说明
- isql自动加载sql脚本
- 自动检测并加载分区脚本
- aix系统开机自动加载脚本
- Vim中自动加载cscope.out
- cscope插件,项目根目录、任意子目录下打开vim自动加载cscope.out
- vim 编写脚本时自动配置添加版权信息
- Vim中自动加载cscope.out(Vim支持cscope)[zz]
- vim 自动添加脚本信息
- MonetDB用户指南5——自动加载脚本
- VIM配置,F5自动运行脚本
- Linux系统开机自动启动脚本。自动加载某些脚本或系统服务
- vim自动插入C++和C函数头的脚本
- Vim中自动加载cscope.out
- vim中session自动保存及加载
- [转]在BBB启动时自动加载dtbo(或执行脚本、运行程序)
- vim 创建Python脚本时候自动补全解释器和编码方法
- 自动打印源代码文件当前行的下一行代码--vim 脚本
- SPORE,一个很好的实现JS命名空间的管理,模块的定义,与自动加载依赖模块的脚本文件