Ⅰ. 插件描述
Analyze Ruby code for structural similaritiesⅡ. 基本信息
|
Ⅲ. 安装方法
使用Vundle管理器安装
在你的.vimrc下添加:Plugin 'prophittcorey/vim-flay'
… 然后在Vim中运行以下命令:
:source %
:PluginInstall
对于Vundle版本 < 0.10.2,请用上面的Bundle替换Plugin。
使用NeoBundle管理器安装
在你的.vimrc下添加:NeoBundle 'prophittcorey/vim-flay'
… 然后在Vim中运行以下命令:
:source %
:NeoBundleInstall
使用VimPlug管理器安装
在你的.vimrc下添加:Plug 'prophittcorey/vim-flay'
… 然后在Vim中运行以下命令:
:source %
:PlugInstall
使用Pathogen管理器安装
在终端中运行以下命令:cd ~/.vim/bundle
git clone https://github.com/prophittcorey/vim-flay
Ⅳ. 文档说明
Vim Flay
Vim Flay analyzes structural similarities within Ruby code and reports code
that is structured similar. This is a great way to find code that is prime for
- Ruby is well known for DRY code practices and vim-flay helps
- code that appears to violate the DRY principle.
Vim Flay attempts to be unobtrusive yet informative. The plugin will mark a
number of lines where code is too similar and when the cursor is placed on
line with a mark there will be a subtle status message within the command bar.
Note, vim-flay ignores the naming of variables and functions and only
analyzes code structure for similarities.

Requirements
First and foremost, vim-flay requires the installation of flay which is a
Ruby gem. Assuming you have Ruby installed, you can install flay like so,
$ gem install flaySecondly, vim-flay assumes you have compiled vim with Ruby support. Many
vim installations come with Ruby support already enabled. You can check your
installation with the following command,
$ vim --version | grep rubyIf you see +ruby then you are good to go. If not, you can check your operating
system's requirements for installing vim with Ruby support. If you are an
Ubuntu user you may not have Ruby support out of the box, but you can easily
install a version of vim that does,
$ sudo apt-get install install vim-noxFinally, vim-flay requires +signs support. Vim Flay uses signs to mark
lines within Ruby source code. Most installations of vim have sign support
but you can check your installation to be sure,
$ vim --version | grep signIf you see +signs in the output there is no problem.
Installation
With the requirements out of the way all you need to do is install the plugin
- If you are a Pathogen user you are in luck because vim-flay is
Pathogen friendly. All you need to do is drop this plugin in yourbundle
folder and you are good to go.
$ cd ~/.vim/bundle/
$ git clone https://github.com/prophittcorey/vim-flay.gitIf you don't have Pathogen set up I highly recommend you check it out. It saves
a lot of headaches when installing vim plugins.
Check out Pathogen here.
Usage
By default there are no mappings. It is up to you to set up your own. I use the
following:
nnoremap <Leader>f :Flay<CR>
The Flay command processes the current file and marks any lines with similar
code.
There are a few other useful commands,
FlayClearclears all marksFlayToggletoggles between Flay and FlayClearFlayListlists all bad line numbers in the current file
For vim-flay help within vim, use :help vimflay. You can test out all of
these commands within vim without a mapping. You can do so by running the
command within vim such as :FlayToggle within normal mode.
Configuration
There are some configurable settings in vim-flay which can help simplify the
usage of the plugin. Below are all settings with their defaults shown. These
settings are also within the vim docs for vim-flay.
g:flay_on_opendefaults to 0, change to 1 to enableg:flay_on_savedefaults to 0, change to 1 to enableg:flay_minimum_massdefaults to 6, change to any number you preferg:flay_piet_textdefaults to ">>", change it to anything you prefer
A note on g:flay_minimum_mass. The default is a number I feel comfortable with
but you may find it to be too sensitive to similarities. If that is the case you
may prefer a number like 10 or 16. You can mess with different numbers until you
find a number that fits your preference.
All of these options are configurable in your .vimrc file. Below are a few
examples of what that would look like,
let g:flay_on_open=0
let g:flay_on_save=1
let g:flay_minimum_mass=10
let g:flay_piet_text="✗"License
The MIT License (MIT)
Copyright (c) 2015, Corey Prophitt.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.