Ⅰ. 插件描述
Automatically reformats/beautifies ruby source code in vim on file save or `ff` keypressⅡ. 基本信息
|
Ⅲ. 安装方法
使用Vundle管理器安装
在你的.vimrc下添加:Plugin 'radovskyb/vim-rubyformat'
… 然后在Vim中运行以下命令:
:source %
:PluginInstall
对于Vundle版本 < 0.10.2,请用上面的Bundle替换Plugin。
使用NeoBundle管理器安装
在你的.vimrc下添加:NeoBundle 'radovskyb/vim-rubyformat'
… 然后在Vim中运行以下命令:
:source %
:NeoBundleInstall
使用VimPlug管理器安装
在你的.vimrc下添加:Plug 'radovskyb/vim-rubyformat'
… 然后在Vim中运行以下命令:
:source %
:PlugInstall
使用Pathogen管理器安装
在终端中运行以下命令:cd ~/.vim/bundle
git clone https://github.com/radovskyb/vim-rubyformat
Ⅳ. 文档说明
# Vim-RubyFormat
vim-rubyformat is a simple vim plugin, that automatically
reformats/beautifies ruby code, either when a ruby file is saved
or when ff is pressed whilst in normal mode.
===========================================================================
Installation:
If using [Vundle Plug-in Manager] for Vim:
Add the following line to your vimrc file:
Plugin 'radovskyb/vim-rubyformat'Launch vim and run :PluginInstall
If using [Pathogen.vim] by [Tim Pope]:
Go to your terminal window and type:
cd ~/.vim/bundle
git clone https://github.com/radovskyb/vim-rubyformat.git===========================================================================
Step 1.
In any .rb (ruby) file, when save is called, the RubyFormat() function should automatically be called. It's as simple as that.
Step 2 (Optional).
Press ff in normal mode to call the RubyFormat() function
===========================================================================
Settings:
For other keybindings, simply bind :call RubyFormat() to your chosen keybinding in your vimrc file.
Example: nnoremap fm :call RubyFormat()<CR>
let g:remove_extra_lines = 2 is the current default, which deletes any
extra blank lines more than 2 in a row. Place in vimrc to change the value.
To disable autoformatting on file save, place let g:rubyformat_on_save = 0
in your vimrc file.
===========================================================================
EXAMPLE AUTO REFORMATS:
Before:
def Hello ( name )
puts "\n-------------"
puts "Hello, #{ name }."
puts '--------------'
endAfter:
def Hello (name)
puts "\n-------------"
puts "Hello, #{name}."
puts '--------------'
end===========================================================================
Before:
[ 1, 2, 3, 4, 5 ].each do | i |
puts "hello"
endAfter:
[1, 2, 3, 4, 5].each do |i|
puts "hello"
end===========================================================================
Before:
[ 1, 2, 3, 4, 5 ].each { | i , b, c | puts "hello" }After:
[1, 2, 3, 4, 5].each { |i , b, c| puts "hello" }===========================================================================
Before:
class Hello
def World( stuff )
end
endAfter:
class Hello
def World(stuff)
end
end===========================================================================
Before:
lambda {puts "hi"
puts "there"
}
lambda {|name|puts "hi"
puts "there"
}After:
lambda {
puts "hi"
puts "there"
}
lambda { |name|
puts "hi"
puts "there"
}===========================================================================
Before:
-> do
puts "true" end
-> {
puts "#{itsTrue} #{orIsIt}"}After:
-> do
puts "true"
end
-> {
puts "#{itsTrue} #{orIsIt}"
}===========================================================================
Before:
if true
# do something
end class Hello
# do something in the class
end
if something
# do something
end if somethingElse
# do something else
endAfter:
if true
# do something
end
class Hello
# do something in the class
end
if something
# do something
end
if somethingElse
# do something else
end===========================================================================