views:

97

answers:

3

Just moving over to vim at the moment. In textmate I could format code by hitting cmd-alt-[. How do I achieve the same in vim?


See the answer below for the command. I found I also need the following in my vimrc so that vim new how to autoindent ruby.

if has("autocmd")
  filetype indent on
endif
A: 

ggVGgq will reformat the entire file according to the current filetype

delimited
I guess ggVG= would do the same.
Omar
I tried ggVGqg and while the document was reformatted it was entirely wrong e.g. first line of first method definition was stuck to the end of the class definition line. I couldn't make any sense of the formatting at all.
opsb
See edit in original question for my solution to the formatting problem.
opsb
+1  A: 

Try:

gg=G

in normal mode.

Maxim Kim
+4  A: 

Vimcasts has a useful screencast on this subject that you may be interested in

gg=G

gg => go to start of file
=  => apply autoformatting
G  => ... to the end of file
Mr. Matt
I tried this in a ruby file and it indented all lines so that they started 8 characters from the left. It completely ignored the original indentation.
opsb
See edit in original question for my solution to the formatting problem.
opsb
Watched the vimcast, it's well worth a look
opsb