Automatically updating the tags

You probably don't want to have to manually run the ctags -R . command every time you make changes to the code. The simplest way to address this is to add the following to your .vimrc file:

" Regenerate tags when saving Python files.autocmd BufWritePost *.py silent! !ctags -R &

The preceding snippet runs ctags -R every time you save a Python file.

You can replace the preceding *.py extension with different file extensions depending on the language you'd like to work with. For example, the following will generate a tags file for C++ files: autocmd BufWritePost *.cpp *.h silent! !ctags -R & 

Get Mastering Vim now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.