[英]How to refresh taglist in vim?
当我对文件进行更改时,例如,添加一个函数,在保存更改后,如何让taglist自动更新其窗口中的“标记列表”?
I adapted my setup from the C++ code completion vim tip . 我从C ++代码完成vim提示改编了我的设置。
map <C-F12> :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .<CR>
When needed, I press Ctrl-F12 to regenerate tags. 需要时,按Ctrl-F12重新生成标签。
If you're using vim-taglist , you could add to your .vimrc
an autocommand for the BufWritePost event to update the taglist window after every save: 如果您正在使用vim-taglist ,您可以在.vimrc
添加BufWritePost事件的自动命令 ,以便在每次保存后更新标记列表窗口:
autocmd BufWritePost *.cpp :TlistUpdate
Haven't tested, but you could try something like: 没有测试,但你可以尝试类似的东西:
au BufWritePre *.cpp ks|!ctags %
Which basically executes ctags when the buffer for a file ending in .cpp
gets saved( :w
). 当以.cpp
结尾的文件的缓冲区被保存时,它基本上执行ctags( :w
)。
http://vim.wikia.com/wiki/Autocmd_to_update_ctags_file http://vim.wikia.com/wiki/Autocmd_to_update_ctags_file
Just add this to your ~/.vimrc 只需将其添加到〜/ .vimrc即可
function! DelTagOfFile(file)
let fullpath = a:file
let cwd = getcwd()
let tagfilename = cwd . "/tags"
let f = substitute(fullpath, cwd . "/", "", "")
let f = escape(f, './')
let cmd = 'sed -i "/' . f . '/d" "' . tagfilename . '"'
let resp = system(cmd)
endfunction
function! UpdateTags()
let f = expand("%:p")
let cwd = getcwd()
let tagfilename = cwd . "/tags"
let cmd = 'ctags -a -f ' . tagfilename . ' --c++-kinds=+p --fields=+iaS --extra=+q ' . '"' . f . '"'
call DelTagOfFile(f)
let resp = system(cmd)
endfunction
autocmd BufWritePost *.cpp,*.h,*.c call UpdateTags()
I did write a little experimental script that automatically and incrementally updates, the "current" tags file on file saving. 我写了一个小的实验脚本 ,自动并逐步更新,“当前”标签文件保存文件。
(The question is actually redundant with Vim auto-generate ctags ) (这个问题实际上是多余的, Vim自动生成ctags )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.