关于taglist的使用技巧,我的编辑器vim+ctags+taglist+(supertab)

本文详细介绍了如何在Vim编辑器中结合ctags和taglist插件进行高效代码导航,同时提及了supertab的整合,提升代码编辑体验。通过设置和配置,实现快速跳转函数、类定义,提升HTML、CSS等项目的开发效率。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<script type="text/javascript"> /*<![CDATA[*/ if(top.location != self.location){ top.location = self.location; } var myref = encodeURIComponent("http://hi.baidu.com/hanframe%5Fip/blog/item/4e4da7ef5a7f2c30adafd539%2Ehtml"); /*]]>*/</script>

<script> <!-- function newUserTipShow(f) { if(f=="0"){//close G("newUserTipSwf").style.width="40px"; G("newUserTip").style.width="40px"; G("newUserTipShadow").style.display="none"; }else{//show G("newUserTip").style.width="220px"; G("newUserTipSwf").style.width="220px"; G("newUserTipShadow").style.display="block"; } } function newUserRegLog(){ var now=new Date(); now.setTime(now.getTime()+5*60*1000); document.cookie="BDSP_REGFLAG=1;expires="+now.toGMTString()+";path=/"; } //--> </script> <script type="text/javascript"> function set_cookie_4_bdtip(index/* start from one */, value){ var bdtip = document.cookie.match(/(^| )BDTIP=([^;]*)(;|$)/); if(!bdtip){ bdtip=new Array(index); for(var i=0,n=bdtip.length;i<n;i++) { if(bdtip[i]=="" || bdtip[i]==null) bdtip[i]=0; if(i == index - 1){ bdtip[i] = value; } } }else{ bdtip = bdtip[2].split('-'); if(index > bdtip.length) bdtip.length= index; for(var i = 0, j = bdtip.length; i < j; i ++){ if(bdtip[i]=="" || bdtip[i]==null) bdtip[i]=0; if(i == index - 1){ bdtip[i] = value; } } } bdtip = bdtip.join('-'); document.cookie = "BDTIP=" + bdtip+ ";expires=Wed, 28-Nov-37 01:45:46 GMT;path=/;domain=.baidu.com"; } </script>
 
 
 


本节所用命令的帮助入口:

:help helptags
:help taglist.txt

上篇文章介绍了在VIM中如何使用tag文件,本文主要介绍如何使用taglist插件。

想必用过Source Insight的人都记得这样一个功能:SI能够把当前文件中的宏、全局变量、函数等tag显示在Symbol窗口,用鼠标点上述tag,就跳到该tag定义的位置;可以按字母序、该tag所属的类或scope,以及该tag在文件中出现的位置进行排序;如果切换到另外一个文件,Symbol窗口更新显示这个文件中的tag。

在VIM中的taglist插件所实现的就是上述类似的功能,有些功能比SI弱,有些功能比SI更强。而且,taglist插件仍在不断完善中!

要使用 taglist 插件,必须满足:

1. 打开VIM的文件类型自动检测功能;
2. 系统中装了Exuberant ctags工具,并且taglist能够找到此工具(因为taglist需要调用它来生成tag文件);
3. 你的VIM支持system()调用;

在本系列第3篇文章(vimrc初步)中,我们使用了VIM自带的示例vimrc,这个vimrc中已经打开了文件类型检测功能;在上篇文章中,我们也已用到了Exuberant ctags;system()调用在一般的VIM版本都会支持(只有suse Linux发行版中出于安全考虑,关闭了此功能),所以我们已经满足了这三个条件。

现在我们到http://www.vim.org/scripts/script.php?script_id=273下载最新版本的taglist plugin,目前版本是4.3。

下载后,把该文件在~/.vim/目录中解压缩,这会在你的~/.vim/plugin和~/.vim/doc目录中各放入一个文件:

       plugin/taglist.vim – taglist插件

       doc/taglist.txt    - taglist帮助文件

:windows用户需要把这个插件解压在你的$VIM/vimfiles或$HOME/vimfiles目录。


使用下面的命令生成帮助标签(下面的操作在VIM中进行):

 

:helptags ~/.vim/doc

 

生成帮助标签后,你就可以用下面的命令查看taglist的帮助了:

 

:help taglist.txt

 

Taglist提供了相当多的功能,我的vimrc中这样配置:

 

   """"""""""""""""""""""""""""""
   " Tag list (ctags)
   """"""""""""""""""""""""""""""
   if MySys() == "windows"                "设定windows系统中ctags程序的位置
     let Tlist_Ctags_Cmd = 'ctags'
   elseif MySys() == "linux"              "设定windows系统中ctags程序的位置
     let Tlist_Ctags_Cmd = '/usr/bin/ctags'
   endif
   let Tlist_Show_One_File = 1            "不同时显示多个文件的tag,只显示当前文件的
   let Tlist_Exit_OnlyWindow = 1          "如果taglist窗口是最后一个窗口,则退出vim
   let Tlist_Use_Right_Window = 1         "在右侧窗口中显示taglist窗口

 

这样配置后,当你输入“:TlistOpen”时,显示如下窗口:


在屏幕右侧出现的就是taglist窗口,你从中可以看到在main.c文件中定义的所有tag:宏、定义、变量、函数等;你也可以双击某个tag,跳到该tag定义的位置;你还可以把某一类的tag折叠起来(使用了VIM的折行功能),方便查看,就像图中macro和variable那样。更多的功能,请查看taglist的帮助页,本文也会介绍一些常用功能。


下面介绍常用的taglist配置选项,你可以根据自己的习惯进行配置:

 

- Tlist_Ctags_Cmd选项用于指定你的Exuberant ctags程序的位置,如果它没在你PATH变量所定义的路径中,需要使用此选项设置一下;

- 如果你不想同时显示多个文件中的tag,设置Tlist_Show_One_File为1。缺省为显示多个文件中的tag;

- 设置Tlist_Sort_Type为”name”可以使taglist以tag名字进行排序,缺省是按tag在文件中出现的顺序进行排序。按tag出现的范围(即所属的namespace或class)排序,已经加入taglist的TODO List,但尚未支持;

- 如果你在想taglist窗口是最后一个窗口时退出VIM,设置Tlist_Exit_OnlyWindow为1;

- 如果你想taglist窗口出现在右侧,设置Tlist_Use_Right_Window为1。缺省显示在左侧。

- 在gvim中,如果你想显示taglist菜单,设置Tlist_Show_Menu为1。你可以使用Tlist_Max_Submenu_ItemsTlist_Max_Tag_Length来控制菜单条目数和所显示tag名字的长度;

- 缺省情况下,在双击一个tag时,才会跳到该tag定义的位置,如果你想单击tag就跳转,设置Tlist_Use_SingleClick为1;

- 如果你想在启动VIM后,自动打开taglist窗口,设置Tlist_Auto_Open为1;

- 如果你希望在选择了tag后自动关闭taglist窗口,设置Tlist_Close_On_Select为1;

- 当同时显示多个文件中的tag时,设置Tlist_File_Fold_Auto_Close为1,可使taglist只显示当前文件tag,其它文件的tag都被折叠起来。

- 在使用:TlistToggle打开taglist窗口时,如果希望输入焦点在taglist窗口中,设置Tlist_GainFocus_On_ToggleOpen为1;

- 如果希望taglist始终解析文件中的tag,不管taglist窗口有没有打开,设置Tlist_Process_File_Always为1;

- Tlist_WinHeightTlist_WinWidth可以设置taglist窗口的高度和宽度。Tlist_Use_Horiz_Window为1设置taglist窗口横向显示;

在taglist窗口中,可以使用下面的快捷键:

 

<CR>          跳到光标下tag所定义的位置,用鼠标双击此tag功能也一样
o             在一个新打开的窗口中显示光标下tag
<Space>       显示光标下tag的原型定义
u             更新taglist窗口中的tag
s             更改排序方式,在按名字排序和按出现顺序排序间切换
x             taglist窗口放大和缩小,方便查看较长的tag
+             打开一个折叠,同zo
-             将tag折叠起来,同zc
*             打开所有的折叠,同zR
=             将所有tag折叠起来,同zM
[[            跳到前一个文件
]]            跳到后一个文件
q             关闭taglist窗口
<F1>          显示帮助

可以用“:TlistOpen”打开taglist窗口,用“:TlistClose”关闭taglist窗口。或者使用“:TlistToggle”在打开和关闭间切换。在我的vimrc中定义了下面的映射,使用“,tl”键就可以打开/关闭taglist窗口:

 

map <silent> <leader>tl :TlistToogle<cr>

Taglist插件还提供了很多Ex命令,你甚至可以用这些命令创建一个taglist的会话,然后在下次进入VIM时加载此会话。

Taglist插件还可以与winmanager插件协同使用,这将在下篇文章中介绍。


[参考文档]

 

1. VIM帮助文件

2. http://vimcdoc.sourceforge.net/

3. taglist帮助文件

[尾记]

本文可以自由应用于非商业用途。转载请注明出处。

原文链接:http://blog.youkuaiyun.com/easwy


类别:linux/unix | 添加到搜藏 | 浏览( 317) | 评论 (0) <script> /*<![CDATA[*/ var pre = [true,'英语单词', '英语单词','/hanframe%5Fip/blog/item/d866a517e29a590fc83d6def.html']; var post = [true,'TCP 连接断连问题剖析(一)','TCP 连接断连问题剖析(一)', '/hanframe%5Fip/blog/item/4933b939be9448f53b87ce1f.html']; if(pre[0] || post[0]){ document.write('<div style="height:5px;line-height:5px;">&nbsp;</div><div id="in_nav">'); if(pre[0]){ document.write('上一篇:<a href="' + pre[3] + '" title="' + pre[1] + '">' + pre[2] + '</a>&nbsp;&nbsp;&nbsp;&nbsp;'); } if(post[0]){ document.write('下一篇:<a href="' + post[3] + '" title="' + post[1] + '">' + post[2] + '</a>'); } document.write('</div>'); } /*]]>*/ </script>
 
上一篇: 英语单词    下一篇: TCP 连接断连问题剖析(一)
 
 
<script type="text/javascript"> /*<![CDATA[*/ function HI_MOD_IN_RELATED_DOC_CALLBACK(arg){ if(arg.length <= 1) return false; var hasMore = arg[0]; var D=function(A,B){A[A.length]=B;} if(arg.length % 2 == 0) D(arg, ["","","",""]); var html = ['<div id="in_related_doc"><div class="tit">相关文章:</div>']; D(html, '<table cellpadding="0" cellspacing="3" border="0">'); for(var i = 1, j = arg.length; i < j; i += 2){ D(html, '<tr>'); D(html, '<td width="15px"><a style="font-size:25px" >&#8226;</a></td><td><a href="http://hi.baidu.com/' + arg[i][3] + '/blog/item/' + arg[i][2] + '.html" target="_blank" title="' + arg[i][0] + '">' + arg[i][1] + '</a>'); D(html, new Array(10).join('/u3000')); D(html, '</td>'); if(arg[i + 1][0] != "") D(html, '<td width="15px"><a style="font-size:25px" >&#8226;</a></td><td><a href="http://hi.baidu.com/' + arg[i + 1][3] + '/blog/item/' + arg[i + 1][2] + '.html" target="_blank" title="' + arg[i + 1][0] + '">' + arg[i + 1][1] + '</a></td>'); else D(html, '<td>&nbsp;</td><td>&nbsp;</td>'); D(html, '</tr>'); } if(hasMore) D(html, '<tr><td colspan="4"><a target="_blank" href="/sys/search?pageno=1&type=7&sort=1&word=vim%D6%D0taglist%CA%B9%D3%C3&item=4e4da7ef5a7f2c30adafd539">更多&gt;&gt;</a></td></tr>'); D(html, '</table></div><div class="line">&nbsp;</div>'); var div = document.getElementById('in_related_tmp'); if(div){ div.innerHTML = html.join(''); while(div.firstChild){ div.parentNode.insertBefore(div.firstChild, div); } div.parentNode.removeChild(div); } window.setTimeout("tracker_init('in_related_doc')",100); } if(RelatedDocData == -1){ // not supported xhr var script = document.createElement('script'); script.type = 'text/javascript'; script.src = '/sys/search?type=8&word=vim%D6%D0taglist%CA%B9%D3%C3&item=4e4da7ef5a7f2c30adafd539&t=' + new Date().getTime(); document.getElementsByTagName('HEAD')[0].appendChild(script); }else if(RelatedDocData == null){ GetAndEval = true; }else{ eval(RelatedDocData); } /*]]>*/ </script>
最近读者:
<script> var g_spAnnony=true; var g_read=[ ["zengzhaonong","c8c47a656e677a68616f6e6f6e67e401","zengzhaonong"], ["duanius","16de6475616e6975730b00","duanius"], ["happyxujiyuan","0621786a797763df01","xjywc"], ["jayklx","4f2e6a61796b6c785903","jayklx"], ["xchinux","2299584368696e75782a00","XChinux"], ["dpxsun","4aac64707873756e1704","dpxsun"], ["jicm1981","80e16a69636d313938314105","jicm1981"], ["ysongcn","be3e79736f6e67636e3504","ysongcn"], {} ]; g_read.length=g_read.length-1; var _rh1=""; var _rh2=""; function wrreader(){ _rh1 += '<table width="100%" ><tr>'; _rh2+='<tr>'; if(g_spAnnony){ _rh1+='<td align="center" width="10%" ><img border="0" width="55" height="55" src="https://i-blog.csdnimg.cn/blog_migrate/54406254f9eed4e545f11f701d50c07e.jpeg"></td>'; _rh2+='<td>&nbsp;</td>'; if(g_read.length>0){ _rh1+='<td align="left" width="12%">'; }else{ _rh1+='<td align="left" width="100%">'; } _rh1+='<a href="https://passport.baidu.com/?login&tpl=sp&tpl_reg=sp&u='+myref+'" target="_self">登录</a>后,您就出现在这里。</td>'; _rh2+='<td>&nbsp;</td>' } if(g_read.length==0){ if(!g_spAnnony){ _rh1+='<td align=left width="100%">最近还没有登录用户看过这篇文章……</td>'; _rh2+='<td>&nbsp;</td>'; } }else{ for(i=0,len=g_read.length;i<len;i++){ _rh1+='<td align="center" valign="bottom" width="10%" class="user"><a href="/'+g_read[i][0]+'" target="_blank"><img border="0" src="http://himg.baidu.com/sys/portraitn/item/'+g_read[i][1]+'.jpg"></a></td>'; _rh2+='<td align="center" valign="top" class="user"><a href="/'+g_read[i][0]+'" target="_blank">'+g_read[i][2]+'</a></td>'; } } _rh1+='<td width="100%"></td></tr>'; _rh2+='<td></td></tr></table>'; document.write(_rh1+_rh2); } wrreader(); </script>
登录后,您就出现在这里。 
  zengzhaonongduaniusxjywcjayklxXChinuxdpxsunjicm1981ysongcn 
 
<script> allkey=allkey+"bc2eaffd83e3fe45d7887da5_4e4da7ef5a7f2c30adafd539_"; </script>
网友评论:
<script> function writecmt(type,id,cmtname,cmturl,portraitId){ var html1=""; if(type==1){ html1="<a href='"+cmturl+"' target='_blank' title='"+cmturl+"'><img border='0' src='http://himg.baidu.com/sys/portraitn/item/"+portraitId+".jpg'><br>"+cmtname+"</a>"; }else{ if(cmtname=="" || cmtname=="匿名网友"){ if(cmturl==""){ html1="<a>匿名网友</a>"; }else{ html1="<a href='"+cmturl+"' target='_blank' title='"+cmturl+"'>"+cmtname+"</a>"; } }else{ if(cmturl==""){ html1="<div class='f14' style='display:inline'>网友:<a>"+cmtname+"</a></div>"; }else{ html1="<div class='f14' style='display:inline'>网友:<a href='"+cmturl+"' target='_blank' title='"+cmturl+"'>"+cmtname+"</a></div>"; } } } document.write(html1); } function filterCmtContent(n){ if(!BdBrowser.isIE){ var defaultfilter1='<span style="filter:glow(color=#000000,strength=2);height:0px;color:#000000">'; var defaultfilter2='<span style="height: 0px; color: rgb(0, 0, 0);">'; var commentDiv=document.getElementById(n); var divs=commentDiv.getElementsByTagName('div'); var d,tmp; for( var i=0,len=divs.length;i<len;i++){ d=divs[i]; if(d.getAttribute('name')=='cmtcontent'){ tmp=d.innerHTML; tmp=tmp.replace(/<span style="filter:glow/(color=#([0-9a-z]{3,6}),strength=2/);height:0px;color:#([0-9a-z]{3,6})">/ig,defaultfilter1); tmp=tmp.replace('<span style="height: 0px; color: rgb(255, 255, 255);">',defaultfilter2); d.innerHTML=tmp; } } } } </script>
<script>filterCmtContent('in_comment');</script>
<script> document.getElementById("spRefURL").value = window.location.href; </script>
发表评论:
姓 名: <script> document.write(" &amp;nbsp;&amp;nbsp; &lt;a href='https://passport.baidu.com/?reg&amp;tpl=sp&amp;return_method=get&amp;skip_ok=1&amp;u=http://hi.baidu.com/sys/reg/' target='_blank'&gt;注册&lt;/a&gt;"); document.write(' | &lt;a href="https://passport.baidu.com/?login&amp;tpl=sp&amp;tpl_reg=sp&amp;u='+myref+'"&gt;登录&lt;/a&gt;'); </script>    注册 | 登录
网址或邮箱: (选填)
<script> G("spBlogCmtor").value=""; G("spBlogCmtURL").value=""; </script>
内 容:
插入表情
<script> var editor=null; try{ editor=new BdEditor("spBlogCmtText",{width:"100%",height:"155px"}); editor.onfocus = function(){hidErr(3);} editor.render(); }catch(e){ var spBlogCmtText = document.getElementById("spBlogCmtText"); var p = spBlogCmtText.previousSibling; while(p && p.nodeType != 1) p = p.previousSibling; if(p && /bdeditor_container/.test(p.id)){ p.parentNode.removeChild(p); } spBlogCmtText.style.display = ''; editor=null; } </script> <script> G("spBlogCmtor").value=G("spBlogCmtor").defaultValue; G("spBlogCmtText").value=""; </script>
验证码:
<script type="text/javascript"> /*<![CDATA[*/ var imgsrc="http://hiup.baidu.com/cgi-bin/genimg?303573706163653132363233333933343130303030303030303030303030303132333630343533353624D650E56005133A6E8A023BC47B0D58"; function f_focus(){ if(G('yanzheng').style.display=="none" ){ G('verifypic').src=imgsrc; G('yanzheng').style.display="block"; } } function newverifypic(){ G("verifypic").src = imgsrc +"&t="+ Math.random(); return false; } /*]]>*/ </script>
     

   
<script> <!-- var hstr="/hanframe%5Fip/brwstat?key1=1"; document.write("<script src='"+hstr+"&key2="+allkey+"'><//script>"); //--> </script> <script src="http://hi.baidu.com/hanframe%5Fip/brwstat?key1=1&key2=bc2eaffd83e3fe45d7887da5_4e4da7ef5a7f2c30adafd539_"></script>
©2009 Baidu
<script> if(document.getElementById("m_blog")) { var imgarray = document.getElementById("m_blog").getElementsByTagName('img'); var imgw = document.getElementById("m_blog").offsetWidth; imgw =imgw-40; for(var i=0; i<imgarray.length; i++){ if(imgarray[i].className=="blogimg" && imgarray[i].width>=imgw) imgarray[i].width=imgw; } } // Fix ff bugs var blog_text = document.getElementById('blog_text'); blog_text.innerHTML = blog_text.innerHTML.replace(/href/s*=/s*("|')?(/././//././/)/gi,"href=$1../$2"); gotoreply(); </script>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值