如何使用CTRL-]在VIM中实现自己的标签跳转? [英] How to implement own tag jump in VIM with CTRL-]?

查看:37
本文介绍了如何使用CTRL-]在VIM中实现自己的标签跳转?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果在 VIM 中使用 :h,它会自动跟随 |links|通过 CTRL+],打开新的帮助主题并维护标签跳转列表(CTRL+T 将返回跳转历史).如何以我自己的文件格式实现这种行为?例如,我希望在 {} 内的文本上使用 CTRL+] 打开一个名为 something.txt 的文件和 CTRL+T 返回.如何实施?

If :h is used in VIM, it will automaticall follow |links| via CTRL+], opening new help topics and maintaining tag jumps list (CTRL+T will go back in jumps history). How to implement such behavior in my own file format? For example, i want CTRL+] on text inside {} to open a file named something.txt and CTRL+T to go back. How to implement this?

推荐答案

这一切都是通过标签完成的.本质上,vim 文件是简单的文本文件,但它们受同一目录中名为tags"的文件的支持.此文件包含的所有条目如下所示:

It's all done with tags. Essentially the vim files are simple text files, but they're supported by a file in the same directory named 'tags'. All this file contains is entries that look like:

'bg'      options.txt     /*'bg'*
'bh'      options.txt     /*'bh'*
'bin'     options.txt     /*'bin'*
'binary'  options.txt     /*'binary'*
'biosk'   options.txt     /*'biosk'*
'bioskey' options.txt     /*'bioskey'*

每一行都是一个标签条目,分为三个字段:标签标识符、标签所在的文件和用于查找该标签的 ex 命令:任何 ex 命令都有效;从上面的例子中可以看出,vim 帮助文件只使用搜索命令:'/'.

Each line is a tag entry, split over three fields: the tag identifier, the file the tag lives in, and the ex command to find that tag: any ex command works; as can be seen in the example above though, the vim help files just use the search command: '/'.

您可以手动编写标签文件,也可以使用诸如 Exuberent ctags 之类的程序来创建自动存档.标签文件通常从您正在编辑的文件所在的同一目录中读取,但您可以在 Vim 中通过调整 'tags' 选项的值来更改它.

You can either write a tags file manually, or use a program such as Exuberent ctags to create the file automatically. The tags file is generally read from the same directory the file you're editing lives in, but you can change this in Vim by adjusting the value of the 'tags' option.

如果你输入:help tags",可以在 vim 中获得更多细节

More details in vim if you type ":help tags"

这篇关于如何使用CTRL-]在VIM中实现自己的标签跳转?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆