Ctags
From charlesreid1
Vimtags: http://vim.sourceforge.net/scripts/script.php?script_id=273
Using Ctags with Vim: http://amix.dk/blog/post/19329
Basics
The Ctags web site is here: http://ctags.sourceforge.net/
From this web site, you can download Ctags and browse through its documentation.
Basic usage of Ctags is usually:
$ ctags $ ctags -R
If you're using Ctags for C++, though, you'll want a more complex call:
ctags -R --sort=1 --c++-kinds=+p --fields=+iaS --extra=+q --language-force=C++ /path/to/target/directory -f /path/to/output/tag_file
Using Ctags with Vim
There are a couple of different ways to use Ctags with Vim. I use two:
Universal Ctags Vim Stuff
There are some things you can put in your .vimrc file that can be used by any plugin/etc using ctags.
Here is how I structure things:
1. Create tag files for any relevant C++ projects
2. Put these tag files in the directory ~/.vim/tags/
3. Specify the directories in which to look for tags
4. Other stuff that's handy to map to keyboard shortcuts
Creating Tag Files
You can create tag files using the "more complex call" specified above.
Tag Directory
The tag directory I use is in ~/.vim/tags. By default, the only place where Ctags looks for tag files is in the current directory, and for large software projects with complex directory structures, adding a tag file to every directory is stupid - not to mention it keeps you from being able to use all the tag information available for a project. Putting the tag information for an entire source code directory structure in a single file allows you to load all of that information in one shot. Putting it in a universal location allows you to load it whenever you want, no matter where you are.
Specifying Tag Directories
In your .vimrc file, you can specify tag files that you want to load every time you run vim:
set tags+=~/.vim/tags/cpp set tags+=~/.vim/tags/uintah_src
Handy Ctag Shortcuts
You can map keyboard shortcuts for Ctag functions that are handy/useful to map.
This will map F6 to create a tagfile for the current directory and put it in the current directory:
map <F6> :!/path/to/ctags -R --sort=1 --c++-kinds=+p --fields=+iaS --extra=+q --language-force=C++ .<CR>
OmniCppCompletion
http://www.vim.org/scripts/script.php?script_id=1520
This Vim plugin allows for C and C++ omni-completion using a Ctags tag file.
You should follow the installation instructions.
Once you have gotten it installed, add the following to your .vimrc:
" =============================================
" OmniCppComplete
" (another Ctags thing...?)
" from http://www.vim.org/scripts/script.php?script_id=1520
" via http://vim.wikia.com/wiki/C%2B%2B_code_completion
set nocp
filetype plugin on
" OmniCppComplete
let OmniCpp_NamespaceSearch = 1
let OmniCpp_GlobalScopeSearch = 1
let OmniCpp_ShowAccess = 1
let OmniCpp_ShowPrototypeInAbbr = 1 " show function parameters
let OmniCpp_MayCompleteDot = 1 " autocomplete after .
let OmniCpp_MayCompleteArrow = 1 " autocomplete after ->
let OmniCpp_MayCompleteScope = 1 " autocomplete after ::
let OmniCpp_DefaultNamespaces = ["std", "_GLIBCXX_STD"]
" automatically open and close the popup menu / preview window
au CursorMovedI,InsertLeave * if pumvisible() == 0|silent! pclose|endif
set completeopt=menuone,menu,longest,preview
Vim TagList Plugin
http://vim.sourceforge.net/scripts/script.php?script_id=273
This Vim plugin is one of the most popular plugins.
Creating libstdc++ Tag File
http://www.vim.org/scripts/script.php?script_id=2358
You can download the above version of the libstdc++ libraries, and use this to create a Ctags tag file for the C++ std lib.
You can follow the instructions on the web page, and put the tag file in ~/.vim/tags and add it .vimrc, by adding it to the list of directories that Ctags looks for tag files (e.g. set tags+=~/.vim/tags/cpp).