Ⅰ. 插件描述
Simple templates plugin for VimⅡ. 基本信息
|
Ⅲ. 安装方法
使用Vundle管理器安装
在你的.vimrc下添加:Plugin 'jelera/vim-template-hands-off'
… 然后在Vim中运行以下命令:
:source %
:PluginInstall
对于Vundle版本 < 0.10.2,请用上面的Bundle替换Plugin。
使用NeoBundle管理器安装
在你的.vimrc下添加:NeoBundle 'jelera/vim-template-hands-off'
… 然后在Vim中运行以下命令:
:source %
:NeoBundleInstall
使用VimPlug管理器安装
在你的.vimrc下添加:Plug 'jelera/vim-template-hands-off'
… 然后在Vim中运行以下命令:
:source %
:PlugInstall
使用Pathogen管理器安装
在终端中运行以下命令:cd ~/.vim/bundle
git clone https://github.com/jelera/vim-template
Ⅳ. 文档说明
=============================
Simple Vim templates plugin
:Author: Adrian Perez <aperez@igalia.com>
This is a simple plugin for Vim that will allow you to have a set of
templates for certain file types. It is useful to add boilerplate code
like guards in C/C++ headers, or license disclaimers.
Installation
The easiest way to install the plugin is to install it as a bundle.
For example, using Pathogen__:
- Get and install
pathogen.vim <_Pathogen>__. You can skip this step
if you already have it installed. cd ~/.vim/bundlegit clone git://github.com/aperezdc/vim-template.git
__ https://github.com/tpope/vim-pathogen
Bundle installs are known to work fine also when using Vundle__. Other
bundle managers are expected to work as well.
__ https://github.com/gmarik/vundle
Updating
Manually
In order to update the plugin, go to its bundle directory and use
Git to update it:
cd ~/.vim/bundle/vim-templategit pull
With Vundle
Use the :BundleUpdate command provided by Vundle, for example invoking
Vim like this::
% vim +BundleUpdate
Configuration
In your vimrc you can put:
let g:templates_plugin_loaded = 1to skip loading of this plugin.let g:templates_no_autocmd = 1to disable automatic insertion of
template in new files.let g:templates_name_prefix = .vimtemplate.to change the name of the
template files that are searched.let g:templates_global_name_prefix = "template:"to change the prefix of the
templates in the global template directory.let g:templates_debug = 1to have vim-template output debug information
Usage
There are a number of options to use a template:
- Create a new file giving it a name. The suffix will be used to determine
which template to use. E.g::
$ vim foo.c
- In a buffer, use
:Template *.footo load the template that would be
loaded for file matching the pattern*.foo. E.g. from within Vim::
:Template *.c
Template search order
The algorithm to search for templates works like this:
- A file named
.vim-template:<pattern>in the current directory. If not
found, goto (2). If there are multiple template files that match a given
suffix in the same directory, the one that is most specific is used.
- Go up a directory and goto (1), if not possible, goto (3).
- Try to use the
=template=<pattern>file supplied with the plugin.
Variables in templates
The following variables will be expanded in templates:
%DAY%, %YEAR%, %MONTH%
Numerical day of the month, year and month.%DATE%
Date in ``YYYY-mm-dd`` format%TIME%
Time in ``HH:MM`` format%FDATE
Full date (date + time), in ``YYYY-mm-dd HH:MM`` format.%FILE%
File name, without extension.%FFILE%
File name, with extension.%EXT%
File extension.%MAIL%
Current user's e-mail address. May be overriden by defining ``g:email``.%USER%
Current logged-in user name. May be overriden by defining ``g:username``.%HOST%
Host name.%GUARD%
A string with alphanumeric characters and underscores, suitable for use
in proprocessor guards for C/C++/Objective-C header files.%CLASS%
File name, without extension, and the first character of every word is
capital%MACROCLASS%
File name, without extension, and all characters are capitals.%CAMELCLASS%
File name, without extension, the first character of every word is capital,
and all underscores are removed.%HERE%
Expands to nothing, but ensures that the cursor will be placed in its
position after expanding the template.