VIM - search tags from several places in the project

Good afternoon,

I usually work on relatively small (less than 20,000 lines of code) projects, which are all inside the same directory, have their own Makefile, and it's pretty easy to work with.

VIM is my preferred editor, and when I open a project, I usually build the ctags list by matching with the F10 key:

map <F10> :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .<CR> 

This allows me to move on to the definition of the / struct / etc variable by moving the cursor over the text and pressing CTRL + ] , as well as using code completion with a drop-down list through OmniCppComplete.

However, now I am working on a slightly larger project that uses LOTS structures. In addition, many of these structures have arrays of other user structures as members, so code completion is a very useful and important tool for me right now.

I have two paths that include many .C and .h files, and they can change from machine to machine. However, on each machine, we have an environment variable in our .bashrc that points to them as follows:

 SDK_SRC_PLUS_HEADERS=/public/sdk THIRD_PARTY_SDK=/private/sdk 

I want VIM to automatically refer to the contents of these additional paths when I try to execute code completion (via the OmniCppComplete VIM built-in function) or go to files in these places when I use CTRL + ] in VIM to go on to define the structure, function , variable, etc.

So, for both of the above paths, I cd in them and generate tags via ctags -R . Then I changed my ~/.vimrc file to include additional tag paths, for example:

 tags=./tags tags+=$SDK_SRC_PLUS_HEADERS/tags tags+=$THIRD_PARTY_SDK/tags 

Then I cd into my project in /home/user1/projects/test , launched VIM and hit F10 in VIM to index it. However, this does not work at all. In fact, this breaks my ability to even use tags only for the project itself (that is: CTRL + ] now does nothing).

Does anyone have any suggestions on how I can have source code completion tags and transitions between definitions using multiple source directories via environment variables?

Thank you all for your time and help!

+4
source share
2 answers

It seems that the problem is that you cannot use environment variables inside the tag settings.

I came up with this as a workaround:

 :let &tags.=expand(",$SDK_SRC_PLUS_HEADERS/tags") 

This might be a little friendlier:

 :exec expand("set tags+=$SDK_SRC_PLUS_HEADERS/tags") 
+1
source

I wanted to add to the solution provided by @sehe.

This is the final set of changes I made to .vimrc . The first lines are for adding extended environment variable paths to my tags variable. The other is for automatically updating tags in case I have to update my SDK and do not want to be able to accidentally use outdated tags:

 " CTAGS tag generation for OmniCppComplete set tags+=./tags exec expand("set tags+=$SDK_SRC_PLUS_HEADERS/tags") exec expand("set tags+=$THIRD_PARTY_SDK/tags") " Can verify taglist is correct via ":set verbose tags?" command " Create a mapping to delete the old tags, re-generate them, and use them map <F10> :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q . \| rm -f $SDK_SRC_PLUS_HEADERS/tags \| ctags -R -f $SDK_SRC_PLUS_HEADERS/tags $SDK_SRC_PLUS_HEADERS/tags \| rm -f $THIRD_PARTY_SDK/tags \| ctags -R -f $THIRD_PARTY_SDK/tags $THIRD_PARTY_SDK/tags \| echo "Done re-generating tags."<CR> 
+1
source

Source: https://habr.com/ru/post/1448041/


All Articles