GithubHelp home page GithubHelp logo

vim-tags's Introduction

Vim-Tags

Vim-Tags version 0.1.0

The Ctags generator for Vim

Copyright (c) 2012-2014 Szymon Wrozynski and Contributors

About

Ctags support is a great feature of Vim. One approach to make use of Ctags is the way of Tim Pope's plugins. For example in Rails projects, Ctags are generated automatically while Bundler is running and installing new gems.

Vim-Tags plugin treats Ctags like more tightly coupled within a concrete project. It creates '.tags' files directly in the root project directory. Also, it can perform tags creation upon each file save through forking - available under Unix-like operating systems. This option, however, may require some tweaking under Windows.

Vim-Tags is under active development. Currently, besides its main features, it provides some support for Ruby/Rails projects (it can generate tags for gems listed in 'Gemfile.lock' file).

Installation

Place in ~/.vim/plugin/tags.vim or in case of Pathogen:

cd ~/.vim/bundle
git clone https://github.com/szw/vim-tags.git

In case of Vundle that would be:

Plugin 'szw/vim-tags'

placed in your .vimrc file

Moreover, Vim-Tags requires ctags utility. On Ubuntu you can install it with:

sudo apt-get install exuberant-ctags

On Mac OSX you could use Homebrew:

brew install ctags

Please, don't forget to star the repository if you like the plugin. This will let me know how many users it has and then how to proceed with further development :).

Ruby Manager

If you are using a Ruby Manager such as chruby, rvm, rbenv etc, be sure to have your Ruby Manager integrated with Vim.

A simple way to check this is by executing bundle show --paths in your Vim in the command-line mode.

:!bundle show --paths

If it shows your current Gems (based on your Gemfile) it is probably working fine.

Usage

The plugin has only one command and a few options described in the Configuration section.

:TagsGenerate

This command will generate one or more tags files but only if the main tags file exists. The presence of that file acts as an indicator actually. By the main tags file I mean the "tags" file collecting tags from all files and subdirectories of the project root directory.

Moreover, this command will also update the tags setting of Vim with all new tags files found in the project root as Vim-Tags caches relative tags paths and updates tags settings automatically.

By default, this command is also executed upon each file save.

Besides the main "tags" file the project may have more tags files for different directories and a special Gemfile.lock.tags file for tags gathered from a Bundler project.

For the first time, when there are no tags files in your project yet, you can force generating them by the bang version of the :TagsGenerate command:

:TagsGenerate!

The bang version of the command forces generation for all "tags" files.

Additionally, you can exclude some directories from the main "tags" file, especially if they contains rarely changed and heavy content, i.e. third-party libraries. Those directories must be placed directly at the project root.

To exclude them, make empty files named exactly after those directories with ".tags" suffixes: e.g. "vendor.tags" for the "vendor" directory. Then, the plugin will be watching modification times of those directories and corresponding tags files and perform tags generation only if necessary.

Vim-Tags can read files containing patterns to exclude from tags generation. By default it seeks among '.gitignore', '.svnignore', and '.cvsignore' files in the current directory. You can change this behavior by setting proper configuration options explained later.

The last but not least feature is the Ruby Bundler support. It is easy and straightforward. If your project root contains "Gemfile.lock" file, the plugin will be generating tags for all your Bundler gems referenced in the Gemfile. Here, "Gemfile.lock" modification time will be taken to find out whether the tags generation is required, just like in the custom directories case explained earlier. The plugin will create "Gemfile.lock.tags" file automatically

Configuration

Vim-Tags assumes that you have 'ctags' utility available in your shell. However it is possible to change or improve shell commands used by the plugin, e.g. in case you have to point a proper binary with absolute path or tweak some options.

Vim-Tags can be configured by setting some global variables in your '.vimrc' file. If you want to have some custom settings valid only for the current project create a local '.vimrc' file with those settings and add the following snippet to your main '.vimrc' file:

set exrc
set secure

This will allow Vim to use your custom .vimrc in the current working directory.

The Vim-Tags available variables are:

  • vim_tags_auto_generate

    • Default: 1

    If enabled, Vim-Tags will generate tags on file saving

      let g:vim_tags_auto_generate = 1
    
  • vim_tags_ctags_binary

    • Default: ctags

    This is the Ctags binary which will be substitued to the commands generating ctags files. Sometimes needs to be customized, e.g. for MacVim I had to set it Homebrew's ctags binary: /usr/local/bin/ctags.

  • vim_tags_project_tags_command

    • Default: "{CTAGS} -R {OPTIONS} {DIRECTORY} 2>/dev/null"

    This command is used for main Ctags generation.

      let g:vim_tags_project_tags_command = "{CTAGS} -R {OPTIONS} {DIRECTORY} 2>/dev/null"
    
  • vim_tags_gems_tags_command

    • Default: "{CTAGS} -R {OPTIONS} `bundle show --paths` 2>/dev/null"

    Command used for Gemfile tags generation.

      let g:vim_tags_gems_tags_command = "{CTAGS} -R {OPTIONS} `bundle show --paths` 2>/dev/null"
    
  • vim_tags_use_vim_dispatch

    • Default: 0

    Vim-Dispatch is a plugin allowing asynchronous calls of system commands. Vim-Tags will try to use it (if found) to perform asynchronous tags generation. Otherwise Vim-Tags will make asynchronous calls by adding & to ctags commands.

      let g:vim_tags_use_vim_dispatch = 0
    
  • vim_tags_use_language_field

    • Default: 1

    Use ctags with --field=+l option necessary for the tag completion in the YouCompleteMe or similar plugins.

      let g:vim_tags_use_language_field = 1
    
  • vim_tags_ignore_files

    • Default: ['.gitignore', '.svnignore', '.cvsignore']

    Files containing directories and files excluded from Ctags generation.

      let g:vim_tags_ignore_files = ['.gitignore', '.svnignore', '.cvsignore']
    
  • vim_tags_ignore_file_comment_pattern

    • Default: '^[#"]'

    The pattern used to recognize comments in the ignore file.

      let g:vim_tags_ignore_file_comment_pattern = '^[#"]'
    
  • vim_tags_directories

    • Default: [".git", ".hg", ".svn", ".bzr", "_darcs", "CVS"]

    The default directories list where the tags files will be created. The first one found will be used. If none exists the current directory ('.') will be taken. The plugin will use that directories as root markers - indicating by their presence the current project root directory.

      let g:vim_tags_directories = [".git", ".hg", ".svn", ".bzr", "_darcs", "CVS"]
    
  • vim_tags_main_file

    • Default: 'tags'

    The main tags file name.

      let g:vim_tags_main_file = 'tags'
    
  • vim_tags_extension

    • Default: '.tags'

    The extension used for additional tags files.

      let g:vim_tags_extension = '.tags'
    
  • vim_tags_cache_dir

    • Default: $HOME

    The directory for cache files (.vt_location).

      let g:vim_tags_cache_dir = expand($HOME)
    

Authors and License

Vim-Tags plugin was written by Szymon Wrozynski and Contributors. It is licensed under the same terms as Vim itself. For more info see :help license.

vim-tags's People

Contributors

josemrb avatar mikedfunk avatar szw avatar xuzhezhaozhao avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vim-tags's Issues

Does not used nested .gitignore files

With a .gitignore file located in bin/ containing:

*
!gitignore

I would expect files or directories in bin/ to be ignored when running TagsGenerate!.
They were not ignored unless I put

bin/*

in a top-level .gitignore file

Empty tags file under .git

OS: RHEL5
Vim: 7.4 (compiled locally)
Ctags: 5.6

Running "ctags -R ." creates the tag file successfully, however whenever I run ":TagsGenerate!" inside Vim, an empty tags file is placed under .git. I saw the other issue where the .gitignore file had entries that began with "!" were affecting the file generation, but it seems to have been fixed and none of my .gitignore entries have ! anywhere in them. Any ideas are greatly appreciated!

customize generate option

For now, I know I can use vim_tags_use_language_field to specify --fields=+l option.

What if I want to specify more complex option? For example, --fields=+l --c-kinds=+p --c++-kinds=+p --extra=+q.

I want to use vim_tags_project_tags_command to achieve that. But it is not really convenient. The {OPTIONS} is modified internally, which means I have to keep {OPTIONS} and specify vim_tags_project_tags_command like this, {CTAGS} -R --fields=+l --c-kinds=+p --c++-kinds=+p --extra=+q {OPTIONS} {DIRECTORY} 2>/dev/null.

Maybe you can change vim_tags_use_language_field to something like vim_tags_generate_options and use it like this,

let g:vim_tags_generate_options='--fields=+l --c-kinds=+p --c++-kinds=+p --extra=+q'.

Thank you :)

Support global gtags?

It seems gtags is another powerful tags tool.
I'm just wondering if you will plan to add gtags supports?
Thanks.

Ignore some directories

Some build systems like sbt, gradle store generated files in a separate directory. These are being parsed and confusing the tags. It would be nice to have a way to ignore files like these. Maybe do this by reading a .vim-tags in the directory or use the .gitignore file.

:TagsGenerate rewrites helptags file incorrectly if doc directory is writeable

When :TagsGenerate is run while a help file is open (including if g:vim_tags_auto_generate == 1 and the tags file there is writeable, vim-tags rewrites it to contain the contents of maketags.awk and makehtml.awk and wipes out the tags for the help files. Since these tags are needed to locate help topics, running :help with this plugin enabled may be enough to not let you find that help topic again.

I filed neovim/neovim#4552 before I realized that vim-tags was the culprit.

Location of tags file

It would be wonderful to have a variable to configure the location where the tags file will be created.

Auto-generating tags does not work after changing the working directory

I often start Vim in my home directory editing a file and then :cd to a project. It seems vim-tags only scans the directory it starts with. So in my case no tags are generated for the project directory.

It would be pretty cool if vim-tags could recognize this and always generate tags for the current directory.

Compatibility with universal ctags

Hey,
first: thanks for your plugin. With vim-tags it is a lot easier to manage tag generation.
I'm using universal ctags since exuberant ctags is very old (last version is from 2009!). Sadly, vim-tags is not compatible with the newest version of universal ctags since the --tag-relative option mustn't be used without any argument (it is necessary to write --tag-relative=yes).

:TagsGenerate only generates some tags compared to :TagsGenerate!

I ran :TagsGenerate!, which created a tags file in the project .git directory. But then when I create new files and save them, the :TagsGenerate command does not generate tags for new php classes. However, if those same classes extend a class already tagged, I can navigate to the class extended from, from inside the new class. This is all attempted just by saving the file, so the tags will be generated automatically. If I manually run :TagsGenerate, I get the same results, the newly created class is not tagged. But If I manually run :TagsGenerate!, it creates tags for the new class. I tried adding a method, and then calling it from another method. When I save, or manually run TagsGenerate, once again, it does not create tags for the method. But if I manually run TagsGenerate!, it does create the tags for the method.

vim-tags has error at rebuildTagFiles()

"src\nov-2015-1gam.cpp" 165L, 3701C written
Error detected while processing function AutoTag:
line 1:
WARNING:root:Traceback (most recent call last):
File "C:\Users\Daddy007\vimfiles\bundle\vim-autotag\plugin\autotag.py", line 262, in autotag
at.rebuildTagFiles()
File "C:\Users\Daddy007\vimfiles\bundle\vim-autotag\plugin\autotag.py", line 253, in rebuildTagFiles
self.updateTagsFile(tags_dir, tags_file, sources)
File "C:\Users\Daddy007\vimfiles\bundle\vim-autotag\plugin\autotag.py", line 247, in updateTagsFile
for l in do_cmd(cmd, self.tags_dir or tags_dir):
File "C:\Users\Daddy007\vimfiles\bundle\vim-autotag\plugin\autotag.py", line 54, in do_cmd
cwd=cwd)
File "C:\Python27\Lib\subprocess.py", line 702, in init
errread, errwrite), to_close = self._get_handles(stdin, stdout, stderr)
File "C:\Python27\Lib\subprocess.py", line 833, in _get_handles
p2cread = self._make_inheritable(p2cread)
File "C:\Python27\Lib\subprocess.py", line 884, in _make_inheritable
_subprocess.DUPLICATE_SAME_ACCESS)
WindowsError: [Error 6] The handle is invalid

E484: Can't open file :messages

Generate tags for git ignored folder

Hello, thanks for developing such good plugin, so far so good, but I have a question, what configuration do I need to use in order to:

  • create tags for all project including vendor/somelib/src
  • .gitignore has vendor/ ignored.

In short, generate ctags for a folder ignored by git?

Thanks

It isn't generating tags

Hi @szw

I don't know why, but it isn't generating ./tags file anymore. If I perform :TagsGenerate it returns very quickly and doesn't generate tags, with :TagsGenerate! it takes a while, but doesn't generate tags neither.

Do you have any idea how to investigate it?

Exclamation marks in .gitignore file prevent generation of tags file

Steps to reproduce

  1. Take a git repostitory
  2. Create .gitignore with e.g. the following content:
/doc/*
!/doc/Doxyfile
  1. Create empty file: .git/tags

When saved, the file .git/tags is still empty. If the line !/doc/Doxyfile is removed from .gitignore, the tags file is sucessfully generated.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.