Vim auto-generate ctags?

"YOU AND THE ART OF ONLINE DATING" is the only product on the market that will take you step-by-step through the process of online dating, provide you with the resources to help ensure success. Get it now!

Au BufWritePost *. C,*. Cpp,*.

H silent! Ctags -R & The downside is that you won't have a useful tags file until it completes. As long as you're on a *nix system it should be ok to do multiple writes before the previous ctags has completed, but you should test that.

On a Windows system it won't put it in the background and it'll complain that the file is locked until the first ctags finishes (which shouldn't cause problems in vim, but you'll end up with a slightly outdated tags file) Note, you could use the append option as tonylo suggests, but then you'll have to disable tagbsearch which could mean that tag searches take a lot longer, depending on the size of your tag file.

Au BufWritePost *. C,*. Cpp,*.

H silent! Ctags -R & The downside is that you won't have a useful tags file until it completes. As long as you're on a *nix system it should be ok to do multiple writes before the previous ctags has completed, but you should test that.

On a Windows system it won't put it in the background and it'll complain that the file is locked until the first ctags finishes (which shouldn't cause problems in vim, but you'll end up with a slightly outdated tags file). Note, you could use the --append option as tonylo suggests, but then you'll have to disable tagbsearch which could mean that tag searches take a lot longer, depending on the size of your tag file.

Ah... good solution. I was using silent! Ctags -R and didn't understand why nothing was happening... I guess you need that second bang.

– cdleary Oct 1 '08 at 0:54 On windows you can always use 'start ctags -R'. It will start ctags in backgroud. – devemouse Sep 1 at 11:12.

Edit: A solution very much along the lines of the following has been posted as the AutoTag vim script. Note that the script needs a vim with Python support, however. My solution shells out to awk instead, so it should work on many more systems.Au FileType {c,cpp} au BufWritePost silent!

-e tags && \ ( awk -F'\t' '$2\! ="%:gs/'/'\''/"{print}' tags ; ctags -f- '%:gs/'/'\''/' ) \ | sort -t$'\t' -k1,1 -o tags. New && mv tags.

New tags Note that you can only write it this way in a script, otherwise it has to go on a single line. There’s lot going on in there: This auto-command triggers when a file has been detected to be C or C++, and adds in turn a buffer-local auto-command that is triggered by the BufWritePost event.It uses the % placeholder which is replaced by the buffer’s filename at execution time, together with the :gs modifier used to shell-quote the filename (by turning any embedded single-quotes into quote-escape-quote-quote). That way it runs a shell command that checks if a tags file exists, in which case its content is printed except for the lines that refer to the just-saved file, meanwhile ctags is invoked on just the just-saved file, and the result is then sorted and put back into place.

Caveat implementor: this assumes everything is in the same directory and that that is also the buffer-local current directory. I have not given any thought to path mangling.

I've noticed this is an old thread, however... Use incron in *nix like environments supporting inotify. It will always launch commands whenever files in a directory change. I.e.

, /home/me/Code/c/that_program IN_DELETE,IN_CLOSE_WRITE ctags --sort=yes *. C That's it.

Perhaps use the append argument to ctags as demonstrated by: vim.wikia.com/wiki/Autocmd_to_update_cta... I can't really vouch for this as I generally use source insight for code browsing, but use vim as an editor... go figure.

To suppress the "press enter" prompt, use :silent.

The --append option is indeed the way to go. Used with a grep -v, we can update only one tagged file. For instance, here is a excerpt of an unpolished plugin that addresses this issue.(NB: It will require an "external" library plugin) " Options {{{1 let g:tags_options_cpp = '--c++-kinds=+p --fields=+imaS --extra=+q' function!

S:CtagsExecutable() let tags_executable = lh#option#Get('tags_executable', s:tags_executable, 'bg') return tags_executable endfunction function! S:CtagsOptions() let ctags_options = lh#option#Get('tags_options_'. &ft, '') let ctags_options .

= ' '. Lh#option#Get('tags_options', '', 'wbg') return ctags_options endfunction function! S:CtagsDirname() let ctags_dirname = lh#option#Get('tags_dirname', '', 'b').'/' return ctags_dirname endfunction function!

S:CtagsFilename() let ctags_filename = lh#option#Get('tags_filename', 'tags', 'bg') return ctags_filename endfunction function! S:CtagsCmdLine(ctags_pathname) let cmd_line = s:CtagsExecutable().' '. S:CtagsOptions().

' -f '. A:ctags_pathname return cmd_line endfunction " ###################################################################### " Tag generating functions {{{1 " ====================================================================== " Interface {{{2 " ====================================================================== " Mappings {{{3 " inoremap ; Run('UpdateTags_for_ModifiedFile',';') nnoremap CTagsUpdateCurrent :call UpdateCurrent() if! Hasmapto('CTagsUpdateCurrent', 'n') nmap tc CTagsUpdateCurrent endif nnoremap CTagsUpdateAll :call UpdateAll() if!

Hasmapto('CTagsUpdateAll', 'n') nmap ta CTagsUpdateAll endif " ====================================================================== " Auto command for automatically tagging a file when saved {{{3 augroup LH_TAGS au! Autocmd BufWritePost,FileWritePost * if! Lh#option#Get('LHT_no_auto', 0) | call s:Run('UpdateTags_for_SavedFile') | endif aug END " ====================================================================== " Internal functions {{{2 " ====================================================================== " generate tags on-the-fly {{{3 function!

UpdateTags_for_ModifiedFile(ctags_pathname) let source_name = expand('%') let temp_name = tempname() let temp_tags = tempname() " 1- purge old references to the source name if filereadable(a:ctags_pathname) " it exists => must be changed call system('grep -v " '. Source_name. ' " '.

A:ctags_pathname.' > '. Temp_tags. \ ' && mv -f '.

Temp_tags. ' '. A:ctags_pathname) endif " 2- save the unsaved contents of the current file call writefile(getline(1, '$'), temp_name, 'b') " 3- call ctags, and replace references to the temporary source file to the " real source file let cmd_line = s:CtagsCmdLine(a:ctags_pathname).' '.

Source_name. ' --append' let cmd_line . = ' && sed "s#\t'.

Temp_name. '\t#\t'. Source_name.

'\t#" > '. Temp_tags let cmd_line . = ' && mv -f '.

Temp_tags. ' '. A:ctags_pathname call system(cmd_line) call delete(temp_name) return ';' endfunction " ====================================================================== " generate tags for all files {{{3 function!

S:UpdateTags_for_All(ctags_pathname) call delete(a:ctags_pathname) let cmd_line = 'cd '. S:CtagsDirname() " todo => use project directory " let cmd_line . = ' && '.

S:CtagsCmdLine(a:ctags_pathname). ' -R' echo cmd_line call system(cmd_line) endfunction " ====================================================================== " generate tags for the current saved file {{{3 function! S:UpdateTags_for_SavedFile(ctags_pathname) let source_name = expand('%') let temp_tags = tempname() if filereadable(a:ctags_pathname) " it exists => must be changed call system('grep -v " '.

Source_name. ' " '. A:ctags_pathname.

' > '. Temp_tags.' && mv -f '. Temp_tags.

' '. A:ctags_pathname) endif let cmd_line = 'cd '. S:CtagsDirname() let cmd_line .

= ' && ' . S:CtagsCmdLine(a:ctags_pathname). ' --append '.

Source_name " echo cmd_line call system(cmd_line) endfunction " ====================================================================== " (public) Run a tag generating function {{{3 function! LHTagsRun(tag_function) call s:Run(a:tag_function) endfunction " ====================================================================== " (private) Run a tag generating function {{{3 " See this function as a /template method/. Function!

S:Run(tag_function) try let ctags_dirname = s:CtagsDirname() if strlen(ctags_dirname)==1 throw "tags-error: empty dirname" endif let ctags_filename = s:CtagsFilename() let ctags_pathname = ctags_dirname. Ctags_filename if! Filewritable(ctags_dirname) &&!

Filewritable(ctags_pathname) throw "tags-error: ". Ctags_pathname. " cannot be modified" endif let Fn = function("s:".

A:tag_function) call Fn(ctags_pathname) catch /tags-error:/ " call lh#common#ErrorMsg(v:exception) return 0 finally endtry echo ctags_pathname .' updated. ' return 1 endfunction function! S:Irun(tag_function, res) call s:Run(a:tag_function) return a:res endfunction " ====================================================================== " Main function for updating all tags {{{3 function!

S:UpdateAll() let done = s:Run('UpdateTags_for_All') endfunction " Main function for updating the tags from one file {{{3 " @note the file may be saved or "modified". Function! S:UpdateCurrent() if &modified let done = s:Run('UpdateTags_for_ModifiedFile') else let done = s:Run('UpdateTags_for_SavedFile') endif endfunction This code defines: ^Xta to force the update of the tags base for all the files in the current project ; ^Xtc to force the update of the tags base for the current (unsaved) file ; an autocommand that updates the tags base every time a file is saved ; and it supports and many options to disable the automatic update where we don't want it, to tune ctags calls depending on filetypes, ... It is not just a tip, but a small excerpt of a plugin.HTH.

There is a vim plugin for this that works really well: vim.org/scripts/script.php?script_id=1343 If you have taglist installed it will also update that for you.

In my opninion, plugin Indexer is better. vim.org/scripts/script.php?script_id=3221 It can be: 1) an add-on for project.tar. Gz 2) an independent plugin background tags generation (you have not wait while ctags works) multiple projects supported.

On OSX this command will not work out of the box, at least not for me. Au BufWritePost *. C,*.

Cpp,*. H silent! Ctags -R & I found a post, which explains how to get the standard ctags version that contains the -R option.

This alone did not work for me. I had to add /usr/local/bin to the PATH variable in . Bash_profile in order to pick up the bin where Homebrew installs programs.

Auto Tag is a vim plugin that updates existing tag files on save. I've been using it for years without problems, with the exception that it enforces a maximum size on the tags files. Unless you have a really large set of code all indexed in the same tags file, you shouldn't hit that limit, though.

Note that Auto Tag requires Python support in vim.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions