vim:在新选项卡中打开标签
是否有插件或脚本可以在新选项卡中打开 ctags 条目?我想将光标放在某个函数上,按 ctrl+] 并在另一个选项卡中打开该条目。我还希望如果我直观地选择一个条目,则 ctrl+] 仍然可以工作并在新的 vim 选项卡中打开。
Is there a plugin or script to open ctags entries in a new tab? I'd like to put my cursor over a function, press ctrl+] and have the entry open in another tab. I'd also like if I visually select an entry, for ctrl+] to still work and open in a new vim tab.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以
CwC-]CwT
来实现该效果
然后您还可以映射该效果:
编辑: 另外,根据您实际想要的内容,不要忘记您可以使用例如在预览中打开标签(
:ptag
) CW}。只是提一下以防万一...You can
C-wC-]C-wT
To achieve that effect
Then you can also map that:
Edit: also, depending on what you actually want, don't forget you can open tags in preview (
:ptag
) with e.g. C-w}. Just mentioning it in case...这里有两个漂亮的临时映射(如果您的标签是由
ctags
生成的):首先,我们在新选项卡中打开当前缓冲区;然后我们尝试跳转到光标下的某个标签(
g
,相当于:tjump
,如果只有一个匹配则直接跳转到该标签,或者提供匹配列表(如果有很多)。优点:
缺点:
情况您能否提供视觉模式映射的用例?
PPS 如果您使用 cscope 生成标签(比
ctags
更好)并使用其 vim 映射,将上面的映射替换为以下映射:Here are two pretty ad-hoc mappings (in case your tags are generated by
ctags
):First we open current buffer in a new tab; then we try to jump to a tag under cursor (
g<C-]>
, which is equal to:tjump
, jumps to the tag directly if there's only one match, or provides a list of matches if there are many).Pros:
Cons:
P.S. Could you provide a use case for visual mode mapping?
P.P.S. If you generate tags with cscope (which is better than
ctags
) and use its vim mappings, replace the above mappings with the following ones:万一有人仍在寻找解决方案。在此解决方案中,当未找到标签时,将不再留下空白选项卡。
In case somebody is still looking for a solution. On this solution when no tag is found no more blank tab will be left.
您可以在 ~/.vimrc 中设置键盘快捷键,'g' 后跟 CONTROL-],如下所示:
您可以通过 :tab 标签 functionname 测试“tab ta”
You can set up a keyboard shortcut, 'g' followed by CONTROL-], in ~/.vimrc as follows:
You can test "tab ta" via :tab tag functionname