vim-autoformat-rails


Ⅰ. 插件描述

VIM autoformatting for ruby, CSS, SCSS, ERB, and cucumber files

Ⅱ. 基本信息

创建日期:  2013-04-11
使用用户:  24
Github星:  12
插件作者:  Kurt Preston

Ⅲ. 安装方法

使用Vundle管理器安装

在你的.vimrc下添加:
Plugin 'kurtpreston/vim-autoformat-rails'
… 然后在Vim中运行以下命令:
:source %
:PluginInstall

对于Vundle版本 < 0.10.2,请用上面的Bundle替换Plugin。

使用NeoBundle管理器安装

在你的.vimrc下添加:
NeoBundle 'kurtpreston/vim-autoformat-rails'
… 然后在Vim中运行以下命令:
:source %
:NeoBundleInstall

使用VimPlug管理器安装

在你的.vimrc下添加:
Plug 'kurtpreston/vim-autoformat-rails'
… 然后在Vim中运行以下命令:
:source %
:PlugInstall

使用Pathogen管理器安装

在终端中运行以下命令:
cd ~/.vim/bundle
git clone https://github.com/kurtpreston/vim-autoformat-rails

Ⅳ. 文档说明

vim-autoformat-rails

vim-autoformat-rails provides simple autoformatting of ruby, CSS, SCSS, ERB, and cucumber files.

It will fix indentation, remove trailing whitespace, and standardize spacing (e.g. always have empty lines between Ruby method declarations, always open CSS curly brackets on the same line as the selector).

Installation

If using Vundle, then add the following line to your vimrc file:

Bundle 'KurtPreston/vim-autoformat-rails'

If not using Vundle, you can install it by copying the repo to your ~/vim/bundle folder.

Autoformatting within VIM

To call the autoformatter on a document, just type == (backslash, equals, equals).

Autoformatting from console

If you want to use vim-autoformat-rails to format multiple files, you can use the included autoformat binary. Just copy it to your path (i.e. /usr/local/bin), then you can run commands such as:

autoformat FILENAME # Format FILENAME
autoformat '*.rb'   # Format all Ruby files in the directory

Customization

Most of the formatting rules are simply regex expressions. If you want to change/remove any the behavior, just add/remove a regex line from the vim-autoformat-rails.vim file.

Examples

CSS

Before:

#selector, input:hover

{

  font-size:13px;
     height     :        20px;     }

After:

#selector, input:hover {
  font-size: 13px;
  height: 20px;
}

Ruby

Before:

def test_function(x)

         if x > 2

           return false
         else
             return true

         end

     end

After:

def test_function(x)
  if x > 2
    return false
  else
    return true
  end
end

添加新评论