Vim-Indexer

Indexer is a Vim plugin that provides painless transparent tags generation and keeps tags up-to date. Tags are generated in background, so you don't have to wait while your tags are being generated.

Consider reading the article Vim: convenient code navigation for your projects, which explains the topic on Indexer + Vimprj usage very thoroughly.

Indexer can work in two ways:

  • Independently;
  • As an add-on for project plugin.

In either way, it provides painless automatic tags generation for whole project(s) and keeps tags up-to-date.

This plugin can be even more useful when it's used together with plugins omnicppcomplete (for c, c++ development), code_complete.vim and other plugins that use tags. And of course you also will be able to jump from function call to its definition just by pressing Ctrl-] or g].

Installation

The project is hosted at bitbucket. Stable versions are at vim.org. Download source code from there and install it as any other Vim plugin.

There are a couple of dependencies:

  • Vimprj plugin;
  • A simple Vim library plugin Vim-DFUtil;
  • ctags. If you use Linux, your distribution is likely to have it in repositories.

Configuration

As I mentioned above, Indexer can work as add-on for Project plugin. Indexer reads project file, parses it and builds tags for all files in project. But it also works fine without Project plugin.

Actually, if you use Project plugin and you use default projects file (~/.vimprojects), then setting Indexer up is very easy: you can just install this plugin, start Vim and open any file from your project. Indexer will detect that opened file is a file from project and automatically generate tags for the whole project. It also set &path and &tags.

If you use Project, but you have different projects file, you should set option g:indexer_projectsSettingsFilename in your vimrc.

If you don't use Project, then you can use .indexer_files file to specify projects and files to index. Default location of this file is ~/.indexer_files. You can change it by modifying variable g:indexer_indexerListFilename.

Syntax of this file is simple, the best way to explain it is probably to show an example:

~/.indexer_files
[CoolProject]

/home/user/cool_project

[AnotherProject]
option:ctags_params = "--languages=c++"

/home/user/another_project/src
/home/user/another_project/lib

I believe the syntax should be obvious: there are two projects, CoolProject and AnotherProject. CoolProject just contains ALL files from /home/user/myproject. AnotherProject is configured in a bit more complicated way: it specifies additional parameter for ctags: –languages=c++. It is needed to make ctags ignore all files except c++ sources. I would recommend you to read and understand ctags help, to be able to write perfect configuration for your projects. You can read it here: http://ctags.sourceforge.net/ctags.html.

The options you need to know first are the following two:

    --languages=[+|-]<list>
    --langmap=<map>[,<map[...]>]

If you have many projects and you are lazy to put every project in this file (like I am), you can put in your ~/.indexer_files something like this:

~/.indexer_files
[PROJECTS_PARENT]
option:ctags_params="--languages=c++,c,python,java"

~/workspace

Workspace directory

The keyword is PROJECTS_PARENT. In this way, each directory in ~/workspace will be interpreted as a separate project: you can open any file from any project in ~/workspace, and the whole project will be indexed.

Please note: suggested ctags options are tested with ctags 5.8. As far as I know, option –languages marked as deprecated in ctags 5.9, but I haven't tested it yet, since the latest version on http://ctags.sourceforge.net is still 5.8. I hope I will have time for this one day.

Multiple projects

Indexer 3.0 and later supports simultaneous work on files from multiple projects. For example, a little story.

Assume we have two projects: “project1” and “project2”, and we use ~/.indexer_files file.

  • you open file1 from project1. Indexer generates tags for all files from project1 and set &tags: ~/.indexer_files_tags/project1
  • you open file2 from the same project1. Indexer just notes that file2 is file from project1. &tags isn't changed.
  • you open file3 from project2. Indexer generates tags for all files from project2 and sets &tags: ~/.indexer_files_tags/project2.
  • you switch to buffer with file1. Indexer does not generate any tags, it just changes &tags to ~/.indexer_files_tags/project1
  • you switch to buffer with file3. Indexer changes &tags back to ~/.indexer_files_tags/project2.

So, you should not care about your projects. It just works. If you have some subprojects, I would recommend to use .vimprj directory with specific settings for your project, in which you can set any options such as &tags, &tabstop, etc. It's up to another plugin actually: Vimprj.

Background tags generation

It works out-of-the-box in Gvim, but not in Vim unfortunately. This is because background tags generation requires your servername to be not empty. (if you don't know what is servername, read :help servername).

If you use Gvim, then servername is GVIM by default. If you use terminal Vim, you need to run vim somehow like that:

$ vim --servername MY_NAME

Of course you can make alias for this command, or do some similar trick.

If servername is empty, then Indexer will work anyway, but you need to wait while ctags works. This is not really noticeable at small projects.

Platforms

It is successfully tested on Vim 7.3, on the following systems:

  • Archlinux
  • Ubuntu 10.4, 12.04
  • Windows XP
  • Mac OS X Lion

More

For further information, such as options and so on, refer to :help indexer.

Discussion

Slava, 2017/08/24 11:26

I do not have an indexer.

The tag file <project_tmp> is only generated.

The <project> tag file does not appear.

My OS - CentOS 7.

What to do?

Dmitry Frank, 2017/08/24 11:33

There is :help indexer-troubleshooting:

If you have troubles, please do the following:

*) put in your vimrc following line:
      let g:indexer_debugLogLevel = 2
*) close Vim, open it again and reproduce the trouble.
*) type:
      :IndexerDebugSave
   and enter filename to save snapshot (for instance, ~/vim_dbg.txt)
*) send to me resulting snapshot file, provide detailed info 
   about troubles

*) don't forget to set g:indexer_debugLogLevel = 0 again, to avoid
   useless memory allocation.
Slava, 2017/08/25 06:44

The problem with the indexer is solved. Let g: indexer_backgroundDisabled = 1

Dmitry Frank, 2017/08/25 06:47

Well, I wouldn't consider that as a “solution”, because you have to wait every time while tags are generated. On very small projects it can be a-ok, on bigger ones it becomes noticeable, and background tags generation is very helpful.

Carousel, 2017/09/04 14:44

I'm afraid I get the same problem as Slava does, only <project>_tmp generated. Here is debug snapshot.

xileF1337, 2019/11/03 23:27

Useful plug-in, but unfortunately it does not work on my Fedora 30 workstation. The problem is that the standard vim executable is not compiled with +clientserver, so the –servername option is not recognized. Instead, one needs to use vimx or gvim -v to get that feature, but it seems you have hard-coded the name vim for the executable into your plugin. Adding let sVimExecutable = 'vimx' in line 649 of file plugin/indexer.vim solves the issue for me. Would it be possible to add a fix for this issue? Thanks in advance!

Enter your comment (please, English only). Wiki syntax is allowed:
   __ __   __ __  _      __  ____   __  __
  / // /  / //_/ | | /| / / / __ \ / / / /
 / _  /  / ,<    | |/ |/ / / /_/ // /_/ / 
/_//_/  /_/|_|   |__/|__/  \___\_\\____/
 
projects/vim-indexer.txt · Last modified: 2015/10/11 14:43 by dfrank
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0