Ⅰ. 插件描述
An plugin to ease typing of repetitive of codeⅡ. 基本信息
|
Ⅲ. 安装方法
使用Vundle管理器安装
在你的.vimrc下添加:Plugin '/message-formatter'
… 然后在Vim中运行以下命令:
:source %
:PluginInstall
对于Vundle版本 < 0.10.2,请用上面的Bundle替换Plugin。
使用NeoBundle管理器安装
在你的.vimrc下添加:NeoBundle '/message-formatter'
… 然后在Vim中运行以下命令:
:source %
:NeoBundleInstall
使用VimPlug管理器安装
在你的.vimrc下添加:Plug '/message-formatter'
… 然后在Vim中运行以下命令:
:source %
:PlugInstall
使用Pathogen管理器安装
在终端中运行以下命令:cd ~/.vim/bundle
git clone https://github.com/vim-scripts/Message-Formatter
Ⅳ. 文档说明
This plugin allows the simplification of repetitive code fragments, allowing
much faster entry; for example, this text
getset List<String> names
gets converted to
public List<String> getNames()
{
return m_names;
}
public void setNames( List<String> val )
{
m_names = val;
}
More importantly, it figures out when you're defining a boolean variable and
replaces the "get" with "is"; thus,
getset boolean old enough
becomes
public boolean isOldEnough()
{
return m_oldEnough;
}
public void setOldEnough( boolean val )
{
m_oldEnough = val;
}
Observe how "old enough" was automatically camel-cased to "oldEnough", and,
when used with "get" or "is", was also capitalized. The same variable can be
used over and over again, each time with (if desired) different formatting
directives; for example, this template pattern
My name is {john::f_fName} and my full name is {{fName} smith::uq_fullName}.
gets expanded to
My name is John and my full name is "JOHN SMITH".
Observe, also, how the "fullName" directive recursively contained and expanded
the fName directive.
In the "getset" example, the "get" is defined as:
Addlocaltemplate get public {::type} {eval '{type}' ==? 'boolean' ? 'is' : 'get'::get}{::cf_property}()n{nreturn m_{c_property};n}
The "set" is defined as:
Addlocaltemplate set public void set{::cf_property}( {::type} val )n{nm_{c_property} = val;n}
And the "getset" is defined simply as:
Addlocaltemplate getset {tem get::getTem}nn{tem set::setTem}
This allows "get" and "set" to be used independently (for read-only or write-only properties, for example) and doesn't require duplication of code to define a separate "getset".