Vim: Difficulty setting up ctags. Source in subdirectories don't see tags file in project root

后端 未结 5 976
伪装坚强ぢ
伪装坚强ぢ 2021-01-29 19:25

I\'m trying to get setup with (exuberant) ctags on Vim today and am having difficulty getting it to work properly. I generate my ctags file on the command line with with:

<
相关标签:
5条回答
  • 2021-01-29 19:45

    Create a .sh file with below code. And run .sh file where you want tags. That will work for sure.

    #!/bin/sh`enter code here`
    filelist=`mktemp`
    find . -name \*.h >> ${filelist}
    find . -name \*.c >> ${filelist}
    find . -name \*.cc >> ${filelist}
    find . -name \*.cpp >> ${filelist}
    find . -name \*.hpp >> ${filelist}
    if [ "$SDKTARGETSYSROOT" != "" ]; then
    find $SDKTARGETSYSROOT/usr/include -name \*.h >> ${filelist}
    fi
    cat ${filelist} | ctags -L -
    
    0 讨论(0)
  • 2021-01-29 19:46
    #!/bin/sh
    
    FREEZE_NAME=/* Give some version number */
    
    mkdir $HOME/ctags/$FREEZE_NAME
    
    V1=/* Software Path */
    
    find $V1 -name "*.h" | xargs /usr/local/bin/ctags -a -f $HOME/ctags/$FREEZE_NAME/h.tags
    
    find $V1 -name "*.c" | xargs /usr/local/bin/ctags -a -f $HOME/ctags/$FREEZE_NAME/c.tags
    
    cd $HOME/ctags/$FREEZE_NAME/
    
    rm -f all.tags
    
    cat c.tags h.tags >> all.tags
    
    sort all.tags > temp.tags
    
    mv temp.tags all.tags
    
    rm -f c.tags h.tags 
    

    Put the above code in a .sh file and run... This will generate your tags for sure.

    0 讨论(0)
  • 2021-01-29 19:49

    add this to .vimrc file set tags=tags;/

    This will check the current folder for tags file and keep going one directory up all the way to the root folder.

    So you can be in any sub-folder in your project and it'll be able to find the tags files.

    0 讨论(0)
  • 2021-01-29 19:57

    If you generate a tags file for every project, you might like this pattern, especially if you share your .vimrc across different machines:

    let repohome=substitute($REPO_HOME, "\/", "\\\\/", "g")                         
    let &tags=substitute(expand("%:p:h"), "\\(".repohome."/.\\{-}\/\\).*", "\\1tags", "")
    

    You would then have to set the environment variable $REPO_HOME in your .bashrc to your main repo directory without the trailing space (e.g. /home/<yourusername>/repos) and it will automatically look for a tags file in each subdirectory of $REPO_HOME with a depth of 1, e.g. /home/<yourusername>/repos/myproj/tags.

    0 讨论(0)
  • 2021-01-29 20:02

    There is an option to tell Vim where to look for tag file.

    I use the following configuration:

    " search first in current directory then file directory for tag file
    set tags=tags,./tags
    

    Extract from help :

    When a tag file name starts with "./", the '.' is replaced with the path of the current file. This makes it possible to use a tags file in the directory where the current file is (no matter what the current directory is). The idea of using "./" is that you can define which tag file is searched first: In the current directory ("tags,./tags") or in the directory of the current file ("./tags,tags").

    For example: :set tags=./tags,tags,/home/user/commontags

    And I keep my current working directory in the top project directory where my tagsfile is generated.

    Use :pwd and then :cd myproj (inside Vim) to go to the directory containing your tags file.

    See :help tags-option for more information on tags path.

    You issue is probably that you are either in the wrong directory, or your tags option is not properly set.

    0 讨论(0)
提交回复
热议问题