Problem with ctags+VIM
过去多啦不再A梦
过去多啦不再A梦 2017-05-16 16:41:54
0
2
656

After generating with ctags -R, you must manually execute set tags=..../tags every time you enter VIM editing. I thought of a way to use ctags -f to put the tags file in the specified place, and then set set tags=.... in vimrc. Finally, I found that the tags file can indeed be found, but when jumping, it is based on the tags file. It comes from the root directory, not the project root directory. Is there any way to avoid setting tags every time?

过去多啦不再A梦
过去多啦不再A梦

reply all(2)
某草草

You should just specify the generated file path when executing the ctags command.

This is how I set the tags options:

set tags+=./../tags,./../../tags,./../../../tags

In this way, if you are not too deep in the project, you can always find the tags file of this project.

PS: taglist and tagbar plug-ins are very useful =w=

Peter_Zhu

In addition to setting " set tags+=./../tags,./../../tags,./../../../tags, you can try the following methods (for example, if the kernel tags are too large, it is best not to load them automatically, so it is not recommended to do this when the project is particularly large)

vim automatically searches for upper-level directories and recursively loads ctags and cscope

The original text is here, I increased the number of directory levels and added GTAGS (refer to GNU golbal)

Note: The [pre-path] of GTAGS in my function (reference: help cscope) is the result of the current directory being :pwd

function! AutoLoadCTagsAndCScope()
    let max = 10
    let dir = './'
    let i = 0
    let break = 0
    while isdirectory(dir) && i < max
        if filereadable(dir . 'GTAGS')
            execute 'cs add ' . dir . 'GTAGS ' . glob("`pwd`")
            let break = 1
        endif
        if filereadable(dir . 'cscope.out')
            execute 'cs add ' . dir . 'cscope.out'
            let break = 1
        endif
        if filereadable(dir . 'tags')
            execute 'set tags =' . dir . 'tags'
            let break = 1
        endif
        if break == 1
            execute 'lcd ' . dir
            break
        endif
        let dir = dir . '../'
        let i = i + 1
    endwhile
endf
nmap <F7> :call AutoLoadCTagsAndCScope()<CR>
" call AutoLoadCTagsAndCScope()
" http://vifix.cn/blog/vim-auto-load-ctags-and-cscope.html
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!