Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Generate ctags incrementally in vim. Juste paste this into your .vimrc.
function! GenerateTagsIncrementally()
python << EOF
import os
print('Generating tags incrementally.')
# Walk the file tree, if a file has an mtime more recent than the tag file,
# add it to the list of files to index.
tags_mtime = os.stat('tags').st_mtime
with open('list', 'w') as fp:
for dirpath, dirnames, filenames in os.walk(os.getcwd()):
for filename in filenames:
full_path = os.path.join(dirpath, filename)
if os.stat(full_path).st_mtime > tags_mtime:
fp.write(full_path + '\n')
# print(full_path) # Files to be indexed.
# Run ctags using the created list of files.
os.system('ctags --recurse --verbose --append --extra=+q --fields=+aimS --c-kinds=+p --c++-kinds=+p -L list')
os.remove('list')
EOF
endfunction
command GenerateTagsIncrementally call GenerateTagsIncrementally()
@Flolagale

This comment has been minimized.

Copy link
Owner Author

Flolagale commented Mar 19, 2013

Just paste this into your .vimrc, it will provide you with a new command:

:GenerateTagsIncrementally

that will use ctags and update the tags only for the files that have a modification time more recent than the tags file modification time.
This snippet uses vim's current working directory to find the files to index and requires Python, Exuberant Ctags and Vim compiled with Python support.

@lvht

This comment has been minimized.

Copy link

lvht commented Mar 2, 2014

I think the magic you use is just the --append option.

You can just use the find command to find all the file modified after the tag file like this:

find . -newer tags #tags is the name of you tag file

However, the option --append does not work well when you delete some code from your source file. Even though a symbol is deleted from the source file, the --append option could not let cags to delete the symbol from the tag file.

@huowa222

This comment has been minimized.

Copy link

huowa222 commented Jul 10, 2019

line 18:
Traceback (most recent call last):
File "", line 5, in no
OSError: [Errno 2] No such file or directory: 'tags'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.