Wiki

by yszheda

View project onGitHub

Tip 102: Configure Vim to Work with ctags

Return to the top: <<Practical Vim>>

Tell Vim Where to Find the tags File

  • The 'tags' option specifies where Vim should look to find a tags file.

References:

# If you open the file in vim,
# then you can \"ayy@a the next line to execute the vim command: 
:h 'tags'
  • inspect the default settings:
    :set tags?
    tags=./tags,tags
    
  • Under certain conditions, if a match is found in the first tags file, Vim won’t even look in the second file.

References:

# If you open the file in vim,
# then you can \"ayy@a the next line to execute the vim command: 
:h tags-option

Generate the tags File

Simple Case: Execute catgs Manually

:!ctags -R
  • create a mapping:
    :nnoremap <f5> :!ctags -R<CR>
    

Automatically Execute ctags Each Time a File is Saved

:autocmd BufWritePost * call system("ctags -R")

Automatically Execute ctags with Version Control Hooks

Effortless Ctags with Git