TextMate 跳转到 VIM 中的函数?

发布于 2024-08-08 18:08:24 字数 186 浏览 4 评论 0原文

最近我一直在尝试使用 vim 而不是 TextMate,而我在 VIM 中最怀念的功能之一是 TextMate 的跳转到方法功能(对于那些不知道的人,请使用 CMD + Shift + T)。环顾四周,我没有看到任何特殊的方法来模拟此功能,并且想知道这里是否有人有过 VIM 中此类功能的经验。

预先感谢您的任何答复

帕特里克

Recently I've been trying my hand at using vim instead of TextMate and one of the features that I've missed most in VIM is TextMate's jump to method function (CMD + Shift + T for those who don't know). From looking around I havn't seen any particular way to emulate this functionality and was wondering if anyone here has had experience with this sort of functionality in VIM.

Thanks in advance for any answers

Patrick

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

怪我入戏太深 2024-08-15 18:08:24

您正在寻找 vim 的“标签”功能...我在这里回答了有关标签的类似问题: 如何在VIM中用CTRL-]实现自己的标签跳转?

You're looking for vim's 'tags' functionality ... I answered a similar question about tags here: How to implement own tag jump in VIM with CTRL-]?

断爱 2024-08-15 18:08:24

此功能已使用 :FufBufferTag 在 fuzzyfinder 中实现。 查看票证

This functionality has been implemented in fuzzyfinder using :FufBufferTag. See the ticket

听,心雨的声音 2024-08-15 18:08:24

我很想听到好的建议,因为我一直使用 Vim,但没有使用过 TextMate。我做了以下稍微重叠的事情。

  1. 搜索 def-space-<函数名称的前几个字母>。因此,要转到函数 foo(在 Python 或 Ruby 中,当然是在同一个文件中),我输入 /def fo 就可以了。我还在 Vim 中启用了增量搜索。

  2. 对我经常访问的功能使用标记。因此,我将ma 处理函数定义,然后'a 稍后再返回。我知道这不是函数定义,但它是一个拐杖。

I'd love to hear good suggestions as I use Vim all the time but haven't used TextMate. I do the following things which slightly overlap.

  1. Search for d-e-f-space-<first few letters of function name>. So to go to function foo (in Python or Ruby, and within the same file of course), I type /def fo and I'm there. I also have incremental search enabled in Vim.

  2. Use marks for functions which I visit often. So I'll ma at the function definition and then 'a back to it later. I know it's not function definitions but it is a crutch.

凉墨 2024-08-15 18:08:24

您可以使用 ctags http://ctags.sourceforge.net/ 创建标签文件
基本上 $ctags -R
然后,一旦你进入 vim :set Tags=/path/to/tagsfile

这也将是任何标签,而不仅仅是类名、方法等。在正常模式下,在方法/类/上按 ctrl-] ,它将跳转到那个位置。

您还可以使用 taglist 插件,它将在侧窗口中显示当前标签。 ctags

you can create a tags file with ctags http://ctags.sourceforge.net/
basically $ctags -R
Then once you're in vim :set tags=/path/to/tagsfile

this will also be any tag so not just class names, methods, etc. In normal mode ctrl-] on the method/class/ and it will jump to that position.

You can also use the taglist plugin which will display current tags in a side window. ctags

叹沉浮 2024-08-15 18:08:24

我遇到了几乎同样的问题,我找到了一个快速而肮脏的解决方案(将其粘贴到您的 .vimrc 中并通过键入 :LS 进行调用)

function! s:ListFunctions()
vimgrep /function/j %
copen
endfunction
command! -bar -narg=0 LS call s:ListFunctions()

如果您需要更多功能,那么 Exuberant Ctags 会为您做得更好

I had pretty much the same problem and I found a quick and dirty solution (paste this in your .vimrc and call by typing :LS)

function! s:ListFunctions()
vimgrep /function/j %
copen
endfunction
command! -bar -narg=0 LS call s:ListFunctions()

If you require more functionality then Exuberant Ctags will do better for you

倾城月光淡如水﹏ 2024-08-15 18:08:24

我使用 CommandT 进行文件搜索,然后使用 / 搜索特定函数。然而,真正的问题是CSS。 Textmate 中的 Cmd Shift T 可以快速跳转到特定的 CSS 类,这可以节省大量时间。

CTags 不支持 CSS 解析,除非你用补丁重新编译(通过 google 找到),但我什至不确定我们是否可以像 Textmate 中那样对 CSS 类进行模糊搜索。我真的很怀念 Cmd Shift T 功能。

I'm using CommandT for file searching, then / to search for a particular function. However, the real issue is with CSS. Cmd Shift T in Textmate enable quick jumps to a particular CSS class, and that is a huge time-saver.

CTags doesn't support CSS parsing, unless you re-compile with a patch (found via google), but I'm not even sure if we can do fuzzy searching for CSS classes like in Textmate. I really miss the Cmd Shift T feature.

轮廓§ 2024-08-15 18:08:24

我编写了一个 TextMate Bundle 命令(例如,您可以轻松地将其分配给 Ctrl+]),该命令查找插入符号下的类或方法的定义,并将其显示在工具提示中,以及文件名和找到它的行。

检查一下:添加 TextMate 的快捷方式以在工具提示中查找类或方法定义
希望您会发现它很有用!

I've written a TextMate Bundle command (you can easily assign it to Ctrl+] for example) that lookup for the definition of the class or method under the caret and displays it in a tooltip, along with the file name and the line where it was find.

Check it out: Add a shortcut to TextMate to lookup a class or method definition in a tooltip

Hope you'll find it useful!

朮生 2024-08-15 18:08:24

这个问题中描述的功能有许多不同的名称,具体取决于 IDE/编辑器:

  • 在 Resharper 中,它被称为“Goto File member”
  • 在 Sublime Text 2 中,它被称为“Goto Symbol”
  • 在 PyCharm 中,它被称为“Goto Symbol”

该功能本质上是相同的尽管在上述所有实现中(我认为在 TextMate 中也非常相似)。该功能会显示方法/函数的交互式列表(并且可能还包括成员变量/属性)。

该列表允许通过键入方法/函数/等的名称进行交互式过滤。该列表通常还允许使用箭头键来选择方法/功能/等。在选定的方法/函数/等的情况下按 Enter 键可导航到当前文件中定义所选方法/函数/等的行。

在这个问题的所有现有答案中,我看到的唯一一个似乎提供了此功能的相当相似的实现是使用命令:

:FufBufferTag 

在 vim 的 FuzzyFinder 插件。

建议使用 taglist 插件的答案不是一个好的解决方案,因为 taglist 插件提供的功能与功能有很大不同。 taglist 插件提供了类似的功能 - 能够查看当前文件中的方法概要,但它不提供实时过滤该列表的交互式方式。 taglist 插件确实允许您搜索标签缓冲区,但这并不像其他编辑器中提供的“转到符号”功能那么方便。

我想在这里提供一个替代建议,即使用命令:

:CtrlPBufTag 

在优秀的 Ctrlp vim 插件。在我看来,这是迄今为止 vim 中当前可用的“Goto Symbol”功能的最佳实现。

The feature described in this question has many different names depending on the IDE/Editor:

  • In Resharper it's called "Goto File member"
  • In Sublime Text 2 it's called "Goto Symbol"
  • In PyCharm it's called "Goto Symbol"

The feature is essentially the same though in all of the above implementations (and I assume it's very similar in TextMate as well). The feature brings up an interactive list of methods/functions (and potentially also includes member variables/properties).

The list allows interactive filtering by typing the name of a methods/functions/etc. The list also usually allows the use of arrow keys to select a method/function/etc. Hitting the enter key with a method/function/etc selected navigates to the line in the current file where the selected method/function/etc is defined.

Of all the existing answers in this question the only one that I see which seems to provide a reasonably similar implementation of this feature is to use the command:

:FufBufferTag 

in vim's FuzzyFinder plugin.

The answer which suggests using the taglist plugin is not a good solution, because the functionality offered by the taglist plugin is quite different from the feature. The taglist plugin offers similar functionality - the ability to view an outline of methods in the currently file, but it does not offer an interactive way to filter that list in realtime. The taglist plugin does allow you to search the tag buffer, but that's not nearly as convenient as the "Goto symbol" functionality offered in other editors.

I wanted to provide an alternative suggestion here, which is to use the command:

:CtrlPBufTag 

in the excellent Ctrlp vim plugin. In my opinion this by far the best implementation of the "Goto Symbol" feature currently available in vim.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文