从 RubyMine 迁移到 Vim - 解释的自动完成 [英] Migrating to Vim from RubyMine - Interpreted Auto completion

查看:61
本文介绍了从 RubyMine 迁移到 Vim - 解释的自动完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

直到上周,我一直在使用 RubyMine 进行 Rails 开发.我知道它有一个 vim 插件,但我一直致力于将我的开发迁移到 vim 和 tmux.我不想继续使用鼠标,VIM 给了我更多的灵活性.我找到了几乎所有我关心的功能的插件和解决方法,除了下面我的第一个屏幕截图中的解释的自动完成"功能.RubyMine 解释整个 rails 应用程序并提供按相关性排序的建议(如您所见,它向我显示了相关类的实例变量和方法以及它包含的模块)然后它显示了(不太相关)在 <代码>对象类.当有方法签名时,它还显示方法签名.

此外,在我的第二个屏幕截图中,您可以看到 RubyMine 如何为核心 Ruby 类提供自动完成功能.

将此与最底部的屏幕截图进行比较.我确实有完成,但没有办法找到我要找的东西.我正在使用 ctags , YouCompleteMe, vim-rails, vim-ruby 并且我也尝试安装 eclim 看看它是否有所作为.

是否有我遗漏的插件可以增强我的自动完成功能?看起来 RubyMine 并没有做一些超级疯狂的事情.如果 pry 在相同的上下文"中运行,它可以给我同样的力量".

第一个屏幕截图(RubyMine 解释的自动完成):

第二个屏幕截图(RubyMine 核心 Ruby 类自动完成):

第三张截图(vim omnifunc + ctags):

解决方案

重要提示此解决方案仅适用于 Ruby 1.9+

我在 https://github.com/zxest/vim-ruby 分叉了 'vim-ruby' 并将其修改为:

  • 方法签名现在显示在完成中.
  • 我禁用了按名称排序的方法.

插件和设置

vim-rails我正在使用 vim-rails https://github.com/tpope/vim-rails

超级标签我正在使用 supertab https://github.com/ervandew/supertab 而不是 YouCompleteMe(在我的问题中提到)虽然 YouCompleteMe 是超级快速和自动的,但目前我的 it 和我的 vim-ruby fork 之间存在一些兼容性问题.>

vim-easytags我正在使用 vim-easytags https://github.com/xolox/vim-easytags

将此添加到您的~/.vimrc

:set tags=./tags;:let g:easytags_dynamic_files = 1

确保在你的项目目录中touch ./tags.

从 vim 发出 :UpdateTags -R **/*.* 以便 easytags 生成您的标签文件.

重新映射omnicomplete

为了弹出omnicomplete,默认情况下,我们必须点击.我通过在我的 ~/.vimrc 中插入以下内容将其重新映射到 :

inoremap <C-x><C-o>

我现在在想要 supertab 完成我的代码时按 tab,当我想要 omnicomplete 触发并为我显示方法签名时按 Ctrl+Space.肯定有更好的方法来整合这个(即让 supertab 在一个点之后调用 omnicomplete)

这是截图!请注意,方法排序关闭允许我的自定义 resize 方法出现在顶部,并且签名现在出现在完成中(以及按下 Enter 时出现在编辑器中!)

Up until last week, I had been using RubyMine for my Rails development. I know it has a vim plugin but I have been working on migrating my development to vim and tmux. I don't want to keep using the mouse and VIM gives me a lot more flexibility. I have found plugins and workarounds for almost all the features I care about except the "interpreted auto complete" functionality in my first screenshot below. RubyMine interprets the whole rails application and offers sorted-by-relevance suggestions (as you can see, it's showing me instance variables and methods for the class in question and the modules it includes) THEN it shows (less relevant) methods available on the Object class. It also shows the method signature when there's one.

Also, in my second screenshot, you can see how RubyMine offers autocompletion for core Ruby classes.

Compare this to the bottommost screenshot. I do have completion but there's no way to find what I'm looking for. I'm using ctags , YouCompleteMe, vim-rails, vim-ruby and I also tried installing eclim to see if it makes a difference.

Is there a plugin I've missed that can enhance my auto completion? It doesn't look like RubyMine is doing something super crazy. pry can give me the same 'power' if it were running in the same 'context'.

First Screenshot (RubyMine interpreted auto complete):

Second Screenshot (RubyMine core Ruby classes auto complete):

Third Screenshot (vim omnifunc + ctags):

解决方案

Important Note This solution only works for Ruby 1.9+

I forked 'vim-ruby' at https://github.com/zxiest/vim-ruby and modified it as such:

  • Method signatures now appear in completion.
  • I disabled sorting by name for methods.

Plugins and Settings

vim-rails I'm using vim-rails https://github.com/tpope/vim-rails

supertab I'm using supertab https://github.com/ervandew/supertab instead of YouCompleteMe (mentioned in my question) although YouCompleteMe is super fast and automatic but there are currently some compatibility issues between my it and my vim-ruby fork.

vim-easytags I'm using vim-easytags https://github.com/xolox/vim-easytags

Add this to your ~/.vimrc

:set tags=./tags;
:let g:easytags_dynamic_files = 1

Make sure to touch ./tags in your project directory.

Issue :UpdateTags -R **/*.* from vim in order for easytags to generate your tags file.

Remap omnicomplete

In order for omnicomplete to pop up, by default, we have to hit <C-X><C-O>. I remapped this to <C-Space> by inserting the following in my ~/.vimrc:

inoremap <C-@> <C-x><C-o>

I now press tab when I want supertab to complete my code and Ctrl+Space when I want omnicomplete to trigger and show method signatures for me. There's definitely a better way to integrate this (i.e. getting supertab to call omnicomplete after a dot)

And here goes the screenshot! Notice that method sorting being off allowed my custom resize method to appear on top and the signatures now appear in the completion (as well as in the editor when enter is pressed!)

这篇关于从 RubyMine 迁移到 Vim - 解释的自动完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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