vim 用ctags时增加当前文件包含的boost头文件属性跳转

1. ~/.vimrc 下增加  

 set tags+=~/.vim/systags  

2. python脚本:

可以保存成python脚本,在代码目录执行脚本即可

#!/usr/bin/python2
# coding: utf-8

import os
import sys
import re

g_boost_path = "/usr/local/include"
g_tags_cmd = "ctags -R --c++-kinds=+p --fields=+iaS --extra=+q -f ~/.vim/systags "

#全局 文件列表
g_path_list = []
#boost 头文件
g_pre_boost_file_list = []
g_pre_sec_boost_file_list = []

def getPathFiles(rootDir): 
    list_dirs = os.walk(rootDir) 
    for root, dirs, files in list_dirs: 
        #for d in dirs: 
        #    print os.path.join(root, d)      
        for f in files: 
            #print os.path.join(root, f) 
            if(f.endswith((".cpp", ".c", ".h", ".hpp"))):
                abspath= os.path.join(root, f)
                g_path_list.append(abspath)

def extractBoostFile(filePath, fileList):
    file = open(filePath)
    while 1:
        lines = file.readlines(100)
        if not lines:
            break
        for line in lines:
            if line.startswith("#include") and -1 != line.find("", line)[0])
                #print "dir: " + incPath
                fileList.append(incPath)
                pass
            else:
                continue

if __name__ == '__main__':
    usrDir = ""
    if len(sys.argv) < 2:
        usrDir = "."
        #print "Usage: getPathFiles path"
    else:
        usrDir = sys.argv[1];
    topPath = os.path.abspath(usrDir)
    if not os.path.isdir(topPath):
        print "dir [" + sys.argv[1] + "] is't exist"
        sys.exit(0)
    getPathFiles(topPath)

    for f in g_path_list:
        extractBoostFile(f, g_pre_boost_file_list)
    for f in g_pre_boost_file_list:
        extractBoostFile(f, g_pre_sec_boost_file_list)

    for i in g_pre_boost_file_list:
        g_tags_cmd += (i + " ")
    for i in g_pre_sec_boost_file_list:
        g_tags_cmd += (i + " ")

    if(not os.path.isfile("~/.vim/systags")):
        os.system(r"touch ~/.vim/systags") 
    #print g_tags_cmd
    os.system(g_tags_cmd)




你可能感兴趣的:(python)