Ⅰ. 插件描述
Simple and flexible template engine.Ⅱ. 基本信息
|
Ⅲ. 安装方法
使用Vundle管理器安装
在你的.vimrc下添加:Plugin 'thinca/template-vim'
… 然后在Vim中运行以下命令:
:source %
:PluginInstall
对于Vundle版本 < 0.10.2,请用上面的Bundle替换Plugin。
使用NeoBundle管理器安装
在你的.vimrc下添加:NeoBundle 'thinca/template-vim'
… 然后在Vim中运行以下命令:
:source %
:NeoBundleInstall
使用VimPlug管理器安装
在你的.vimrc下添加:Plug 'thinca/template-vim'
… 然后在Vim中运行以下命令:
:source %
:PlugInstall
使用Pathogen管理器安装
在终端中运行以下命令:cd ~/.vim/bundle
git clone https://github.com/thinca/vim-template
Ⅳ. 文档说明
template is a Vim plugin to read the template file automatically when the
edit of the file is newly started. Template file is selected to match the
file name to open. Also, you can run any command after the open.
Example:
If the template files are located as follows:
~/.vim/template
|-- doc
| `-- template.txt
|-- plugin
| `-- template.vim
|-- template.java
|-- template.rb
|-- template.vim
|-- template_spec.rb
`-- templateTest.java
Template is loaded as follows.
Open file Template that is loaded
--------- -----------------------
foo.vim template.vim
plugin/foo.vim plugin/template.vim
Foo.java template.java
FooTest.java templateTest.java
foo.rb template.rb
foo_spec.rb template_spec.rb
foo.txt (None)
doc/foo.txt doc/template.txt
And, you can execute commands when template loaded.
Examples:
Defines replacing keywords:
autocmd User plugin-template-loaded call s:template_keywords()
function! s:template_keywords()
%s/<+FILE NAME+>/=expand('%:t')/g
%s/<+DATE+>/=strftime('%Y-%m-%d')/g
" And more...
endfunction
Evaluate by vim and expand the inside of <%= %>:
autocmd User plugin-template-loaded
silent %s/<%=(.{-})%>/=eval(submatch(1))/ge
Expand the date it is written in the following template.
<%= strftime('%Y-%m-%d') %>
Move the cursor to <+CURSOR+>:
autocmd User plugin-template-loaded
if search('<+CURSOR+>')
| execute 'normal! "_da>'
| endif
Filtered by an external command:
autocmd User plugin-template-loaded silent! :%!erb
autocmd User plugin-template-loaded silent! :%!php
Latest Version:
https://github.com/thinca/vim-template