ubuntu下安装ctags和taglist

本文指导如何在Ubuntu上安装ctags和taglist插件。首先通过sudo apt-get install ctags安装ctags,然后在项目目录下使用ctags -R *生成tags文件。在vim中使用ctags进行代码导航,如vim -t tag。接着,从官方文档安装taglist,将解压后的doc和plugin目录复制到~/.vim/,并运行:helptags命令。在vim中,使用<Tab>或<Backspace>在taglist和编辑区间切换,通过<CR>、o等快捷键进行tag操作。

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

set tags=/你的目录/tags,tags;$HOME  

1.首先安装ctags
sudo apt-get install ctags 
关于ctags的使用
在想要查看的文档下使用
1. $ctags -R *(对所有文档进行-R(递归的查找))
2.$ vim -t tag (请吧tag替换为你想要查找的名称比如main)
用#define定义的宏
枚举型变量的值
函数的定义、原型和声明
名字空间(namespace)
类型定义(typedefs)
变量(包括定义和声明)
类(class)、结构(struct)、枚举类型(enum)和联合(union)
类、结构和联合中成员变量或函数
3.进入一个文档可以查看文件的内容,并且通过c+]可以进入函数的定义(),c+t可以返回。
注意:在运行vim的时候,必须在tags生成的目录下,如果不在使用vim 的时候要加上set tags =路径
部分引用自以下两个博客
 
2.根据vim的文档来安装taglist
1.首先下载 taglist
2.解压出两个目录doc和plugin,拷贝到~/.vim/下,即生成 ~/.vim/doc~/.vim/plugin两个文件夹, 启动vim运行:helptags命令来执行taglist的help文件,如果没有这步,你不能够调到taglist的帮助文档
使用taglist
1.你可以让taglist在你编辑文本的时候打开,你可以选择一个tag(一个变量,一个函数,一个类都可以成为一个tag)并且跳转到它哪里,taglist会在你编辑文档的时候,自动的生成tag.
2.你可以在编辑中自动的打开需要的taglist,设置快捷键
为了跳转到一个tag到新的window中,按o
-------------------------------------------------------------------------------------
可以通过命令吧其他文件内容添加到自己的taglist中
1.使用:TlistAddFiles和:TlistAddFileRecursive命令
第一个例子
:TlistAddFiles /my/project/dir/*.c
把dir中所有c语言文件添加到Taglist中.注;如果文件过大会出现延迟,需等待一会。
第二个
:TlistAddFilesRecursive /my/project/dir *.c
注:这里在*.c前有一个空格,有两个参数,第一个是目录,第二个是c语言文件,递归的添加.
-------------------------------------------------------------------------------------------
                                                * taglist-keys*                          taglist-keys
Taglist window key list                                                                        taglist 窗口key列表
The following table lists the description of the keys that can be used           下表描述了在taglist窗口中使用的key
in the taglist window.                                                      

  Key           Description                           key                    描述

  <CR>          Jump to the location where the tag under cursor is                <CR> (carrige return)             跳转到当前光标所指定tag定义的位置
                  defined.
  o             Jump to the location where the tag under cursor is                     o        在新窗口中,跳转到当前光标所指定tag定义的位置
                defined in a new window.
  P             Jump to the tag in the previous (Ctrl-W_p) window.       p        跳转到之前窗口的tag
  p             Display the tag definition in the file window and         P        在文件窗口中显示tag定义并且在taglist窗口保持自身的光标 
                keep the cursor in the taglist window itself.        
  t             Jump to the tag in a new tab. If the file is already        t        跳转到新的tab中的tag,如果文件早就在tab中打开了,直接跳转到之前的tab
                opened in a tab, move to that tab.
  Ctrl-t        Jump to the tag in a new tab.                  Ctrl-t     跳转tag到新的tab
  <Space>       Display the prototype of the tag under the cursor.      <Space>     在光标下面展示tag的原型,对于文件名,显示全部的路径名,文件类型和tags的数目。对于tag类型,写是tag类型和tags的个数
                For file names, display the full path to the file,                         
                file type and the number of tags. For tag types, display the
                tag type and the number of tags.
  u             Update the tags listed in the taglist window          u        在taglist窗口中,更新tags列表
  s             Change the sort order of the tags (by name or by order)     s         改变tags的顺序(通过名字或顺序)
  d             Remove the tags for the file under the cursor         d         在文件光标下移除tags
  x             Zoom-in or Zoom-out the taglist window            x       隐藏或出现taglist窗口
  +             Open a fold                         +       打开一个fold
  -             Close a fold                        -       关闭一个fold
  *             Open all folds                       *          打开所有的folds
  =             Close all folds                         =          关闭所有的folds
  [[            Jump to the beginning of the previous file           [[          跳转到之前文件的开头
  <Backspace>   Jump to the beginning of the previous file        <Backspace>      跳转到之前文件的开头
  ]]            Jump to the beginning of the next file             ]]          跳转到下一个文件的开头
  <Tab>         Jump to the beginning of the next file            <Tab>      跳转到下一个文件的开头
  q             Close the taglist window                     q        关闭taglistwindow
  <F1>          Display help                       <F1>        显示帮助文档
  
The above keys will work in both the normal mode and the insert mode.   以上keys在普通模式和插入模式都会工作
 
---------------------------------------------------

 
可以通过 ctrl+w快捷键或者鼠标点击在Taglist窗口和编辑区之间切换焦点
let Tlist_Use_Right_Window =1.显示在右边
"
"taglist 设置                                                                             
"
let Tlist_Auto_Open=1                                                                     
set tags=tags                                                                             
set autochdir                                                                             

"只显示当前文件的tags
let Tlist_Enable_Fold_Column = 0
let Tlist_Show_One_File = 1                                                           
"设置taglist宽度
let Tlist_WinWidth=40
"taglist 窗口是最后一个窗口,则退出VIM
let Tlist_Eixt_OnlyWindow=1
"在VIM窗口右侧显示taglist窗口                                                             
let Tlist_Use_Right_Window=1    


这里要注意

set tags=/你的目录/tags,tags;$HOME  
防止出现跳转不了的情况:tag not found

### 安装 Taglist 插件 为了在 Ubuntu 20.04 上安装并配置 Vim 的 Taglist 插件,需要先确保已经安装了必要的依赖项。这包括 `ctags` `vim` 及其开发包。 #### 准备工作 通过以下命令来安装所需的软件包: ```bash sudo apt update sudo apt install vim ctags -y ``` 这些命令会更新本地的包列表,并安装最新版本的 Vim Ctags 工具[^2]。 #### 获取 Vundle 管理器 接着,使用 Git 来获取 Vundle 这一 Vim 插件管理器。Vundle 是一种流行的用于管理加载 Vim 插件的方式之一。 ```bash mkdir -p ~/.vim/bundle git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim ``` 这段脚本创建了一个目录结构供 Vundle 使用,并克隆仓库至该位置[^4]。 #### 配置 `.vimrc` 编辑用户的 Vim 配置文件(通常是位于家目录下的`.vimrc`),加入如下几行以启用 Vundle 支持以及添加 Taglist 插件: ```vim set nocompatible " be iMproved, required filetype off " recommended by Vundle " 设置编码格式 set encoding=utf-8 " 文件编码设置为 utf-8 call plug#begin('~/.vim/plugged') Plug 'preservim/taglist' call plug#end() let Tlist_Ctags_Cmd='/usr/bin/ctags' " 指定使用的 ctags 命令路径 let TList_GainFocus_On_ToggleOpen=1 " 切换打开关闭时获得焦点 let Tlist_Close_On_Select=1 " 当选中标签后自动关闭窗口 nnoremap <F8> :TlistToggle<CR> ``` 上述代码片段定义了如何初始化插件、指定了 Taglist 插件的位置以及其他一些自定义选项[^3]。 完成以上更改之后,在终端运行 `vim` 并输入`:PluginInstall` 或者重启 Vim 让新的配置生效即可成功安装 Taglist 插件。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值