← Back to Upcase

Navigating Ruby Files with Vim


(Bruno Bruno) #1

Just as the vim-ruby bundle supplies motions for jumping between module, class, and method definitions, it also supplies text objects for operating on these constructs. The im object selects inside of a method definition.

[demo]

That’s exactly the command we were looking for! If we use am instead, it selects all of the method, not just the method body. If your code includes docstring-style comments, then these are also selected by the vam text object. How cool is that?

To summarize: im selects inside the current method, while am selects around the current method. If we use an uppercase M, then we can operate on classes and modules instead of methods. And to complete the table: ir and ar operate on rubyblocks.

Can’t use these object selects. Vim doesn’t understand them. What could be wrong?


(Ben Orenstein) #2

You may be able to get some help on this here, but I bet you’d have even better luck opening an issue on the repo for the plugin that’s not working for you.

Also, when you do that, they’re going to tell you that you haven’t given them nearly enough information to help you debug it, so I’d recommend including things like:

  • Many more details of your environment (OS? Vim version? Plugin version?)
  • What you’ve tried so far and the results
  • Any error messages you’re seeing

Imagine you’re posting to a forum staffed by mechanics stating “My car won’t start. What could be wrong?”

The answer is “One of a bajillion things. More details required.”


(Bruno Bruno) #3

The solution was to update vim (7.4) and/or vim-ruby.


(Drew Neil) #4

It’s likely that updating to the latest version of vim-ruby fixed your problem. I’ve had these mappings working in Vim 7.3 for ages before 7.4 came out.


(Charlieanna ) #5

[], ]], [[ commands arent working me. :frowning: