Vim脚本以特定行号打开文件 [英] Vim script to open file at certain line number

查看:30
本文介绍了Vim脚本以特定行号打开文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用 emacs,其中有人已经设置了配置,但是因为我更喜欢 vim,所以我想在 vim 中做同样的事情.在 emacs 中,当用户输入快捷方式时,emacs 会打开一个新的拆分,并在新拆分中显示与该功能相关的数据,该数据位于前一个文件中的光标下方.所有后续信息都显示在同一个拆分窗口中.

I am currently using emacs where someone had already setup the configurations, but because I like vim better, I wanted to do the same in vim. In emacs when a user enters a shortcut, emacs opens a new split and shows the data related to that function in the new split, which is under the cursor in the former file. All subsequent info is shown in the same split window.

我想在 vim 中做同样的事情.当我将光标移到文件中的函数名称上时,它应该在水平拆分中拉出关联的辅助文件,并转到该函数名称与关联数据一起出现的行号.

I wanted to do the same in vim. When I take the cursor over a function name in a file, it should pull up the associated secondary file in a horizontal split and goto the line number where that function name appears with the associated data.

我如何开始编写这样的脚本?是否可以完全使用 vim 脚本来做到这一点?我是否需要在可以获取行号的一侧编写 perl 脚本?我从哪里开始学习这些东西?

How can I start writing such a script? Is it possible using entirely vim scripts to do this? Do I need to write perl scripts on the side which can get me the line number? Where do I start learning this stuff?

推荐答案

这适用于各种场景;这取决于您的关联数据"是什么.如果是函数的文档,请看:h K.

This is possible for various scenarios; it depends on what your "associated data" is. If it’s the documentation for the function, then see :h K.

如果您生成了 ctags(:h ctags,可用于多种语言),您可以使用标签跳转(<C-]> 和 <代码>).例如,您可以在 C 源文件和头文件之间跳转.

If you’ve generated ctags (:h ctags, available for several languages), you can use tag-jumping (<C-]> and <C-t>). E.g., you can bounce between C source and header files.

各种插件都有自己的方法来弹回相关文件.请参阅 vim-rails 以获取用于跳转到控制器、模板、模型等之间关联的许多命令的示例.

Various plugins have their own means to bounce around associated files. See vim-rails for examples of many commands for jumping to associations between controllers, templates, models, etc.

跳转到分割窗口的标准vim命令在:h windows中有描述.您可能对 :ptag 感兴趣,以便在预览窗口中查看标签.

The standard vim commands for jumping into split windows are described in :h windows. You may be interested in :ptag to see the tag in a preview window.

这篇关于Vim脚本以特定行号打开文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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