ctags
ctags
看到一个视频介绍vim的,看到视频中使用ctags,可以很快速的在定义的类跳转,所以对于编程来说,确实是一个非常好用的功能。
ctags是什么
Ctags is a tool that makes it easy to navigate large source code projects. It provides some of the features that you may be used to using in Eclipse or other IDEs, such as the ability to jump from the current source file to definitions of functions and structures in other files. Ctags will make it much easier to find the Linux kernel files that you have to modify for your CSE 451 projects. Ctags also supports many languages besides C, so you may find it useful for future projects.
Ctags should already be installed on CSE instructional servers such as forkbomb
and attu
. Ctags is first run on its own to generate a “tags” file, then it is invoked from within another Linux text editor such as Emacs or Vim.
简单点说就是对编程中定义的类的一种标记
安装
前面说了它是一个工具,所以需要安装了
1 | sudo pacman -Ss ctags |
生成
这些ctags从哪里来,当然需要手动生成了
cd
to the root directory of your code:
Run Ctags recursively over the entire directory to generate the tags
file.
1 | ctags -R . |
例如在我的目录下生成ctags
1 | cd ~/Documents/code |
使用
在vim中可以使用ctrl+n
来进行补全,它会搜索之前出现过得单词。
但是我只想找ctags呢?使用ctrl+x ctrl+]
进行ctags的补全。
跳转到ctags使用ctrl+]
回到跳转前的位置ctrl+o
或者使用默认标记``
这样还不够好,因为每次都只能在生成之后才有ctags,也就是说在编写程序时,无法找到新添加的类等
所以加入一个自动化执行生成ctags的命令到vimrc文件中
1 | au BufWritePost *.sh,*.hs,*.py silent! !ctags -R & |