Async plugin for Vim/NeoVim to ease the use of ctags/gtags.
It is used for generate and maintain tags for you with multiple platform support, tested on Windows/Linux/macOS.
gen_tags.vim
will detect SCM(git, hg, svn) root and use it as the project root path.
Generate/Update ctags and gtags will run in background.
gen_tags.vim
also provide a gtags completion source for nvim-completion-manager and deoplete.nvim
It's optional, if you don't use ncm or deoplete, just ignore it 😄
GNU global(aka gtags) is more powerful than ctags, which support definition, reference, calling, called, include, string and etc, but ctags only support definition.
As we can use GNU global why did I still support ctags in this plugin?
That's because GNU global only support 6 languages (C, C++, Yacc, Java, PHP4 and assembly) natively.
ctags can support more languages(41 showed on the website).
Actually global can support more languages with Pygments plugin parser, for more details please refer PLUGIN_HOWTO.pygments
in global document.
-
Add
NeoBundle 'jsfaint/gen_tags.vim'
to your vimrc
Then launchvim
/nvim
and run:NeobundleCheck
-
Add
Plug 'jsfaint/gen_tags.vim'
to your vimrc
Then launchvim/nvim
and run:PlugInstall
-
Traditional method
Unzip the zip file under your .vim(*unix) or vimfiles(windows) directory.
-
:GenCtags
Generate ctags database
-
:EditExt
Edit an extend configuration file for this project, use for add third-party library ctags database
The extend database will be generate automatically.e.g.: For libpcap under
e:\src\libpcap-1.3.0
add the following content toext.conf
e:/src/libpcap-1.3.0
-
:ClearCtags
:ClearCtags Remove tags files. :ClearCtags! Remove all files, include the db dir
GTAGS support the third-party library by set an environment variable GTAGSLIBPATH
But you can take a more straightforward way to do the same thing, by create a symbol link of the library
-
Linux/macOS
ln -s /usr/include/ .
-
Windows
mklink /J include C:\TDM-GCC-32\include
-
:GenGTAGS
Generate GTAGS
-
:ClearGTAGS
:ClearGTAGS Remove GTAGS files :ClearGTAGS! Remove all files, include the db dir
ctrl+]
is the default mapping support by Vim for definition
The following mapping is set for GTAGS find function which use cscope interface (if_cscope
).
Ctrl+\ c Find functions calling this function
Ctrl+\ d Find functions called by this function
Ctrl+\ e Find this egrep pattern
Ctrl+\ f Find this file
Ctrl+\ g Find this definition
Ctrl+\ i Find files #including this file
Ctrl+\ s Find this C symbol
Ctrl+\ t Find this text string
g:loaded_gentags#ctags
Set to 1 if you want to disable ctags support
g:loaded_gentags#gtags
Set to 1 if you want to disable gtags support
g:gen_tags#ctags_bin
Set location of ctags. The default is 'ctags'
g:gen_tags#ctags_opts
Set ctags options. The -R
is set by default, so there is no need to add -R
in g:gen_tags#ctags_opts
.
The default g:gen_tags#ctags_opts
is '', you need to set it in your vimrc 😄
g:gen_tags#use_cache_dir
This option only works for scm-repo.
Set the path of tags. If this variable is set to 1, gen_tags.vim
will use cache direcotry to store tags.
The default g:gen_tags#use_cache_dir
is 1, you need to set it in your vimrc.
0:
SCM repo:
git <project folder>/.git/tags_dir
hg <project folder>/.hg/tags_dir
svn <project folder>/.svn/tags_dir
non-git: $HOME/.cache/tags_dir/<project name>
1:
$HOME/.cache/tags_dir/<project name>
g:gen_tags#gtags_split
Set gtags find display behavior. The default g:gtags_split
is ''.
'' means don't split the display.
'h' means horizontal splitting.
'v' means vertical splitting.
g:gen_tags#ctags_auto_gen
Auto generate ctags when this variable is 1 and current file belongs to a scm repo.
The default g:gen_tags#ctags_auto_gen
is 0
g:gen_tags#gtags_auto_gen
Auto generate gtags when this variable is 1 and current file belongs to a scm repo.
The default g:gen_tags#gtags_auto_gen
is 0
g:gen_tags#blacklist
A list to set the blacklist, if the path in blacklist is equal gen_tags#find_project_root()
, the generation of ctags/gtags will be skipped.
The default g:gen_tags#blacklist
is []
e.g.: You can set it in your vimrc as below, it will blacklist $HOME
dir
let g:gen_tags#blacklist = ['$HOME']
g:gen_tags#verbose
Verbose mode to echo some message
The default g:gen_tags#verbose
is 0
g:gen_tags#ctags_prune
Prune tags from tagfile before incremental update
The default g:gen_tags#ctags_prune
is 0
- GenTags#CtagsLoaded
There are two events will be triggered after the ctags was loaded
autocmd User GenTags#CtagsLoaded echo "hello world"
- GenTags#GtagsLoaded
There are two events will be triggered after the gtags was loaded
autocmd User GenTags#GtagsLoaded nnoremap gd <c-]>
The idea comes from @butterflyfish in gen_tags.vim#32
Thanks for reading :)
If you like this plugin, please star it on github!
And one more thing, bug reports and pull-requests are greatly appreciated :)