debian9.6安装exuberant-ctags实现vim函数或者结构体定义跳转并用内核代码测试

 1,介绍

很多人用在windows上用sourceinsight,但很多公司都是用破解版,我之前在通用电气工作时,大家都不会用盗版的,因为sourceinsight软件不是免费的,这个可能就是国内企业和国外企业的区别吧。

也不知道是什么原因,很多人将vim的认识停留在了只能用键盘,所以很多程序员宁可用破解版的sourceinsight,也不用免费的vim。

下载内核,是为了测试,是否可以用。

下面我将使用一个小辅助工具exuberant-ctags,看看官网(http://ctags.sourceforge.net/)对它的定义:

Ctags generates an index (or tag) file of language objects found
 in source files that allows these items to be quickly and easily
 located by a text editor or other utility. A tag signifies a 
language object for which an index entry is available (or, 
alternatively, the index entry created for that object). 

 简单理解,就是弄了一个目录表,等下我将展示一下。

2,安装

guoyanzhang@bogon:~/tag$  sudo apt-get install exuberant-ctags

3,下载内核

官网:https://www.kernel.org/

我下载的是:linux-4.20.2

4,解压

guoyanzhang@bogon:~/tag$ sudo apt-get install exuberant-ctags
guoyanzhang@bogon:~/tag$ tar xvf linux-4.20.2.tar

 5,建立tags

guoyanzhang@bogon:~/tag/linux-4.20.2/kernel$ ctags -R .
guoyanzhang@bogon:~/tag/linux-4.20.2/kernel$ head tags 
!_TAG_FILE_FORMAT	2	/extended format; --format=1 will not append ;" to lines/
!_TAG_FILE_SORTED	1	/0=unsorted, 1=sorted, 2=foldcase/
!_TAG_PROGRAM_AUTHOR	Darren Hiebert	/[email protected]/
!_TAG_PROGRAM_NAME	Exuberant Ctags	//
!_TAG_PROGRAM_URL	http://ctags.sourceforge.net	/official site/
!_TAG_PROGRAM_VERSION	5.9~svn20110310	//
ACCT_TIMEOUT	acct.c	77;"	d	file:
ACTION_ONLY	seccomp.c	187;"	d	file:
ACTIVE_CACHELINE_MAX_OVERLAP	dma/debug.c	473;"	d	file:
ACTIVE_NODE_FRACTION	sched/fair.c	1271;"	d	file:

-R,是recurse,是递归的意思,.是当前目录。可以是用

guoyanzhang@bogon:~/tag/linux-4.20.2/kernel$ man ctags

6,测试使用

随便打开一个.c文件

guoyanzhang@bogon:~/tag/linux-4.20.2/kernel$ vim profile.c

原文:

 使用ctrl+]到定义处:

使用ctrl+t返回:

还是挺不错的。

7,补充功能

可以跳转到你想看的函数处:vim -t tag,如果tag有多个,会列出来让你选的。

如:

guoyanzhang@bogon:~/tag/linux-4.20.2/kernel$ vim -t profile_init

结果:

效果还不错。

8,多屏

-o水平,-O垂直

如下:

guoyanzhang@bogon:~/tag/linux-4.20.2/kernel$ vim exit.c smp.c workqueue.c rseq.c  -o

结果:

guoyanzhang@bogon:~/tag/linux-4.20.2/kernel$ vim exit.c smp.c workqueue.c rseq.c  -O

结果:

关闭所有文件,使用:qall,可以拖动分界线,改变大小。

参考1:https://blog.csdn.net/ballack_linux/article/details/71036072

参考2:https://blog.csdn.net/swrjlxc/article/details/79683472

参考3:https://blog.csdn.net/nickol51/article/details/12981541

猜你喜欢

转载自blog.csdn.net/weixin_39465823/article/details/86511420