The Art of Vim: Vim for Rails Developers


This is a companion discussion topic for the original entry at https://thoughtbot.com/upcase/videos/vim-for-rails-developers-the-art-of-vim

Working through the screencast “The Art of Vim: Vim for Rails Developers” I ran into an issue with :Rfind no longer existing and expecting there to be a few differences between the screencast and the plugin at present, figured I’d document some of these for interested parties working through that screencast and running into/searching for things like “Not an editor command: Rfind events”. I welcome corrections to this, as I’m documenting differences as I figure them out myself.

The readme has all of this information too, but if you’re not looking to dig through documentation, here’s a short guide to which things look different as I follow the screencast.

The advice that “all of the commands are namespaced under a capital R” no longer seems the case. Many of the commands namespaced under :R remain in place, referred to in the documentation as the “classic” versions, but given the removal of :Rfind, I wasn’t certain they would remain in future versions.

:Rfind is replaced by vim’s :find . The documentation explains that ‘the standard Rails load path is prepended to ‘path’, enabling |:find| to work’. ‘:find ’ successfully took me to my Product model and let me tab complete other related files.

:Runittest is, as of today, still an acceptable way to get to the unit test but is replaced by :Eunittest in the documentation. Similarly, :Econtroller replaces :Rcontroller and :Efunctionaltest replaces :Rfunctionaltest. To modify these commands, E is replaced by S for splits, V for vertical splits, T for opening in a new tab and D for reading the file into the current buffer, giving commands like :Vfunctionaltest. Again, RVunittest as given in the screencast still did the job. To jump to and from the unit test for a model or the functional test for a controller, you can also use “:A” as these tests are the designated “alternate file” which this command jumps to. This command can be combined with the same split modifiers, giving us “:AS” or “:AV”.

Running “:Rake” did not output directly into the editor as advised in the screencast, it dropped me back to terminal, ran the tests, then ENTER took me back to vim, though the documentation suggests this is not expected behaviour and this may just be me.

This is fantastic (and thanks @JoshBrodieNZ for the extremely useful update). The only thing I don’t see here is good semantic code completion – in particular, I want to be able to view a function’s signature after I type it, or just type @object. and see a list of available methods on the object. YouCompleteMe looks like it should be the way to do this, but it’s not working for me out of the box in a rails app. From the README it looks like it might only work well for C-family languages? Does anyone have this working in their rails setup?

Where it was gone?

@captain_zoom, I’ve spent a lot of time experimenting with different Vim autocomplete solutions (autocomplpop, neocomplete, YouCompleteMe), and I don’t think there’s a great option available for semantic completion in Vim for Ruby at the moment. Getting semantic completion for Ruby through YouCompleteMe requires running an Eclipse server in the background, and I found the benefits weren’t worth the effort to get it set up and to keep it running all the time while you’re working.

There’s some discussion right now on the NeoVim project about building a better, non-blocking autocomplete functionality. The authors of neocomplete and YouCompleteMe have been involved, and while it looks promising, the discussion hasn’t yielded any new code yet.

thanks @geoffharcourt, that’s great info – I figured there was no easy solution here or I would have heard of it. Keeping my fingers crossed for NeoVim. In the meantime, however, maybe you have an opinion on this question I just posted:

How can I display Rails “function hints” (method signature) snippets or expansions?

Same question, basically, but watered down to just method argument completion (i.e., just matching by name rather than having to know the class of an object and suggest methods based on that). Seems like this could be done pretty straightforwardly with snippets, at least for the standard Rails methods – what do you think? I’m still not aware of an existing solution.

I messed around with this for more hours than I’d like to admit and never came to a solution that was satisfactory.