Vim Tips Wiki
No edit summary
 
(Change to TipImported template + severe manual clean)
Line 1: Line 1:
 
{{review}}
 
{{review}}
  +
{{TipImported
{{Tip
 
 
|id=1299
 
|id=1299
  +
|previous=1298
|title=autocmd to update ctags file
 
  +
|next=1300
|created=August 9, 2006 6:52
+
|created=August 9, 2006
 
|complexity=basic
 
|complexity=basic
 
|author=kilgore trout
 
|author=kilgore trout
 
|version=n/a
 
|version=n/a
 
|rating=4/1
 
|rating=4/1
|text=
 
To automatically update the ctags file when a file is written, I have added this to my .vimrc
 
 
 
 
function! UPDATE_TAGS()
 
 
let _f_ = expand("%:p")
 
 
let _cmd_ = '"ctags -a -f /dvr/tags --c++-kinds=+p --fields=+iaS --extra=+q " ' . '"' . _f_ . '"'
 
 
let _resp = system(_cmd_)
 
 
unlet _cmd_
 
 
unlet _f_
 
 
unlet _resp
 
 
endfunction
 
 
 
 
autocmd BufWrite *.cpp,*.h,*.c call UPDATE_TAGS()
 
 
 
 
I am rather certain that this can be improved, but this works...
 
 
However, if someone knows how to launch the system command in the background, that would be an improvement as the editor is stalled until the update completes. Usually, that isn't a serious impact if the file is not huge, but that would be a help.
 
 
 
 
 
 
}}
 
}}
 
To automatically update the ctags file when a file is written, I have added this to my vimrc:
   
  +
<pre>
== Comments ==
 
 
function! UPDATE_TAGS()
to run a command in background you may take a look on this script:
 
 
let _f_ = expand("%:p")
http://www.vim.org/scripts/script.php?script_id=1582
 
 
let _cmd_ = '"ctags -a -f /dvr/tags --c++-kinds=+p --fields=+iaS --extra=+q " ' . '"' . _f_ . '"'
 
let _resp = system(_cmd_)
 
unlet _cmd_
 
unlet _f_
 
unlet _resp
 
endfunction
 
autocmd BufWrite *.cpp,*.h,*.c call UPDATE_TAGS()
  +
</pre>
   
 
==Comments==
(not tested by my yet)
 
 
To run a command in the background you may try script {{script|id=1582}}.
   
'''Anonymous'''
 
, August 9, 2006 15:53
 
 
----
 
----
Since I wrote it, I prefer wimscript&#35;1343
+
Since I wrote it, I prefer {{script|id=1343}}.
   
The big advantage, that I see, is that simply running ctags -a on a written file leaves behine in the tags file tags for items you've just deleted before writing the file.
+
The big advantage, that I see, is that simply running <tt>ctags -a</tt> on a written file leaves behind in the tags file tags for items you've just deleted before writing the file.
[/scripts/script.php?script_id=1343 vimscript&#35;1343] removes all entries for the file you've just written and *then* runs ctags -a
+
{{script|id=1343}} removes all entries for the file you've just written and ''then'' runs <tt>ctags -a</tt>.
   
vim--AT--cemery.org.uk
 
, August 10, 2006 0:47
 
 
----
 
----
<!-- parsed by vimtips.py in 0.618062 seconds-->
 

Revision as of 04:38, 28 December 2007

Tip 1299 Printable Monobook Previous Next

created August 9, 2006 · complexity basic · author kilgore trout · version n/a


To automatically update the ctags file when a file is written, I have added this to my vimrc:

function! UPDATE_TAGS()
  let _f_ = expand("%:p")
  let _cmd_ = '"ctags -a -f /dvr/tags --c++-kinds=+p --fields=+iaS --extra=+q " ' . '"' . _f_ . '"'
  let _resp = system(_cmd_)
  unlet _cmd_
  unlet _f_
  unlet _resp
endfunction
autocmd BufWrite *.cpp,*.h,*.c call UPDATE_TAGS()

Comments

To run a command in the background you may try script script#1582.


Since I wrote it, I prefer script#1343.

The big advantage, that I see, is that simply running ctags -a on a written file leaves behind in the tags file tags for items you've just deleted before writing the file. script#1343 removes all entries for the file you've just written and then runs ctags -a.