Reformat Ruby source code in vim?

J

John Lam

I'm in the process of converting to vim from emacs to help save my
hands. I'm using the excellent vim-ruby gem to syntax color my code.

One thing that I haven't figured out how to do yet in vim is
reformatting source code. I do this in emacs via ESC-CTRL-Q . It's
really useful during refactoring when moving code fragments from one
place to another.


Thanks!
-John
http://www.iunknown.com
 
K

Kent Sibilev

ggVG=

I'm in the process of converting to vim from emacs to help save my
hands. I'm using the excellent vim-ruby gem to syntax color my code.

One thing that I haven't figured out how to do yet in vim is
reformatting source code. I do this in emacs via ESC-CTRL-Q . It's
really useful during refactoring when moving code fragments from one
place to another.


Thanks!
-John
http://www.iunknown.com
 
J

John Lam

Ah yes - I'm still learning about motions, as well as visual mode. Now
I just have to download this information into my fingers :)

One other thing - is it possible to syntax color a ruby instance
method in vim? I spent some time this morning tweaking my .vimrc to
color things the same way the Vibrant Ink theme in Textmate does, but
the Ruby syntax file in vim doesn't seem to attempt to try and pick
out method names where there's an explicit receiver (eg.
foo.method_name).

Thanks,
-John
http://www.iunknown.com
 
R

Robert Retzbach

It would be interesting to see how textmate does this, cause I can't
think of a way to determine whether foo.method_name is an instance
method or a class method for example.
 
J

James Edward Gray II

It would be interesting to see how textmate does this, cause I can't
think of a way to determine whether foo.method_name is an instance
method or a class method for example.

def foo.method_name... is always a singleton class method, isn't it? ;)

James Edward Gray II
 
J

James Edward Gray II

lucky escape ;)

Not at all. That's why I said "singleton class" in the first place.

Hey man, all this singleton class stuff is just finally starting to
sink into my brain, don't set me back on the path to enlightenment! ;)

James Edward Gray II
 
J

James Edward Gray II

I think I read you know.
Do you mean when defining
def Foo.x
it does not matter if Foo is a class or anyting else, the
"singleton method"
is defined on behalf of the "Object"?

I'm not sure I understood you here. What I was saying is, whenever
you see:

def abc.some_method
# ...
end

You can be sure that some_method() was just defined as a singleton
method of abc. This is often used to make "class methods" in Ruby,
but that's really just applying a familiar term to a Ruby concept.

It's always a singleton method being defined, as I understand it.

James Edward Gray II
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,285
Latest member
CryptoTaxxSoftware

Latest Threads

Top