Search code examples
javascriptrubyvimcontent-assist

How to Content Assist Ruby or JavaScript in Vim?


I'd like to know if it's possible to content assist script languages like Ruby or JavaScript in Vim.

If it is possible, how can I do that?

Do I have to compile the vim source to turn on the 'rubyinterp' option?


Solution

  • What you call "content assist" (Eclipse background?) is called "Omni completion" in Vim. It is part of a larger family of completions simply called "Insert mode completion" and you can read all about it in :h ins-completion.

    There are two big differences with most IDEs completion mechanisms, though:

    • Vim's built-in completion mechanism can't be automatic: you need to press specific shortcuts for the completion menu to appear. If you want automatic completion, you'll need a plugin: NeoComplCache, SuperTab, AutoComplPop or the younger YouCompleteMe. There are others, so try vim.org.

    • Vim doesn't "understand" your language like IDEs do. Vim is a generic text editor geared toward programming but it doesn't have the ability to parse your code and really understand what you mean or follow your scope or dependency tree. Because of that, completion may be a little fuzzy. So don't get your expectations too high.

    You don't need anything special to complete JavaScript but, AFAIK, Vim must be compiled with Ruby support to provide Ruby completion. How to get a proper Vim build depends on your platform, which we don't know.

    In both languages, hitting <C-x><C-o> (in insert mode) after method_name. should open a completion menu that works more or less like those in other editors/IDEs.