Ⅰ. 插件描述
Makes creating partials in your code a breeze!Ⅱ. 基本信息
|
Ⅲ. 安装方法
使用Vundle管理器安装
在你的.vimrc下添加:Plugin 'jbgutierrez/partial'
… 然后在Vim中运行以下命令:
:source %
:PluginInstall
对于Vundle版本 < 0.10.2,请用上面的Bundle替换Plugin。
使用NeoBundle管理器安装
在你的.vimrc下添加:NeoBundle 'jbgutierrez/partial'
… 然后在Vim中运行以下命令:
:source %
:NeoBundleInstall
使用VimPlug管理器安装
在你的.vimrc下添加:Plug 'jbgutierrez/partial'
… 然后在Vim中运行以下命令:
:source %
:PlugInstall
使用Pathogen管理器安装
在终端中运行以下命令:cd ~/.vim/bundle
git clone https://github.com/jbgutierrez/vim-partial
Ⅳ. 文档说明
# vim-partial
Partial plugin is a tool developed to help you break down your code into partials.
Usage
Simply select some lines on Visual mode, hit <leader>x, enter the desired
partial location and the plugin will place the appropriate replacement.
Let me show you:

Note:
Did you find this plugin useful? Please star it and
share
with others.
Configuration
You can tweak the behavior of Partial by setting a few variables in yourvimrc file.
Default Mapping
The default mapping to extract a partial is <leader>x in visual mode.
The same mapping will dispose an existing partial in normal mode.
You can easy map it to other keys. For example:
vmap <Leader>p :PartialExtract<cr>
nmap <Leader>p :PartialDispose<cr>g:loaded_partial
Partial is loaded only once. Set this to 1 to force Partial to reload every
time its file is sourced.
g:partial_templates
Common file extensions are supported (Markup: .dust, .erb, .haml, .slim -
Stylesheets: .css, .less, .sass, .scss) and you can widen this list by
declaring a dictionary like so:
let g:partial_templates = {
\ 'ejs': '<%% include %s %%>',
\ 'hbs': '{{> %s }}'
\ }g:partial_templates_roots
Partial works with a list of usual roots for keeping your templates.
If you happen to use an uncommon root folder you can extend this list
like so:
let s:partial_templates_roots = [
\ 'stylus',
\ 'tmpls'
\ ]g:partial_keep_position
Cursor stays on the same position after replacement. Set this to 0 if you want
to continue with the edition of the partial file.
g:partial_use_splits
New windows for partials are closed after being created. Set
this to 1 if you want to keep the partial in a new window.
g:partial_vertical_split
Partial uses horizontal splits. Set this to 1 if you prefer vertical splits.
g:partial_create_dirs
Partial creates directories as required. Set this to 0 if you don't want
Partial to create new directories.
Implementation details
After triggering :PartialExtract the editor will:
- throw an error if the file type is not supported (you may want to expand this list!)
- suggest a folder with the same name as the file you are working in (without extensions)
- throw an error if the file exists (you can overcome this error by triggering
:PartialExtract!) - ensure the file has the proper extension(s) and create intermediate directories as required
- set partial path relative to the templates folder and dispose any preceding
underscores on the partial name - save the partial content getting rid of unneeded leading spaces and tabs
- make the replacement
Partial tries to set suffixesadd and includeexpr onBufEnter to navigate to partials under the cursor with gf.
Bugs
Please report any bugs you may find on the GitHub issue tracker.
Contributing
Think you can make Partial better? Great!, contributions are always welcome.
Fork the project on GitHub and send a pull request.
Credits
This isn't new. I've borrow the core idea from the following two plugins:
- vim-rails - highly recommended
- rails-partial - sublime users
License
Partial is licensed under the MIT license.
See http://opensource.org/licenses/MIT
Happy hacking!