← Back to Upcase

Navigating Within Ruby Files


(Upcase ) #1
You can download a cheat sheet and install instructions for all of the tools shown in this video. Transcript Ruby motions Here's a typical ruby file. It contains a module, class, and several method definitions. These are some of the main buildi...
This is a companion discussion topic for the original entry at https://thoughtbot.com/upcase/videos/navigating-within-ruby-files

(Carles Jove I Buxeda) #2

This may be an odd question, but how do you actually type [ or ] on Vim? I’m on a spanish keyboard, and I’ve tried with either shift, ctrl, alt and fn + the key where [ is placed. Nothing works for me, and I haven’t even found answers on google. Thanks!


(Nicholas T ) #3

Hope this will help you. http://stackoverflow.com/questions/8015231/vim-annoyance-with-keyboard-layouts


(Carles Jove I Buxeda) #4

Thank you @NicholasTD07 ! This looks like a really source source of information. I’ll carefully read it and post here what I come up with for reference.


(Jonathan Wallace) #5

I can’t find the link for the cheatsheet. Is that still available?


(Letz Shair 😀) #6

How does one debug the fact that hitting % doesn’t do anything when on the d of a word do in a ruby file? Here’s my vim config folder:


(Alex Shelmire) #7

Note that the plugin textobj-rubyblock depends on kana/vim-textobj-user, so you should install that plugin first.


(mattmartini) #8

Really useful video. I’m having trouble with the module and method text objects.

    im
    am
    iM
    aM

When I try to invoke one of them (say vam) I get the error message:

E117: Unknown function: <SRN>106_wrap_a

or 106_wrap_i for vim

I have the necessary plug-ins loaded and var and vir work.

How do I troubleshoot this?


(mattmartini) #9

I noticed something unexpected. Using var to highlight a block, then using ar and ir should expand and contract the selection. However ir does not contract the selection.

Using your example:

module Foo
  class Bar
    def baz
      [1,2,3].each do |i|
        i + 1
      end
    end
  end
end
  1. Starting on the line with each and hitting vir the inside of the baz method is selected as expected.
  2. Now typing ar expands the selection to the whole baz method (from def to end).
  3. However, typing ir now does nothing.
  4. Typing ar at this point will expand the selection to the Bar class.
  5. Again ir does nothing at this point.
  6. Once again typing ar will expand the selection to the whole module.
  7. Now typing ir will shrink the selection to the inside of the module.
  8. At this point ar will expand to the whole module.
  9. Here ir ar will contract and expand the selection, but only at the top level. If we try to type ir twice it only contracts once.

I suspect that because the blocks are nested once you are at 2. you have highlighted the baz method (around the previously selected inside) when you invoke ir it does nothing because it says you are already at the inside of the class Bar and therefore nothing happens.

What is odd is that I used the same text as the video but the behavior is different. I tried this on a number of real world ruby files with the same effect.

How do I troubleshoot this?