When I format a PHP file in vim it’s ok, but when I format a Ruby file, VIM format code bad.
For example:
class PostsController < ApplicationController
skip_before_filter :authorize, :only => [ :index, :show ]
def index
@posts = Post.all
end
def show
@post = Post.find(:first, :conditions => [ "id = ?", params[:id]], :include => [ :user, :category, :gallery ])
@photos = Photo.where(:gallery_id => @post.gallery.id).all
end
end
When I enter the command gg=G, I get.
class PostsController < ApplicationController
skip_before_filter :authorize, :only => [ :index, :show ]
def index
@posts = Post.all
end
def show
@post = Post.find(:first, :conditions => [ "id = ?", params[:id]], :include => [ :user, :category, :gallery ])
@photos = Photo.where(:gallery_id => @post.gallery.id).all
end
end
Please help me.
To get Ruby indenting working you need to provide indenting configuration. Vim itself is not able to indent Ruby code, you could set the indentexpr variable to some similar language (like basic), but you wont be happy with results. Check your smartindent and indentexpr variables:
In my case they are set:
The best way to configure vim for ruby is to use vim-ruby plugin: https://github.com/vim-ruby/vim-ruby