|Author:||Adrian Perez <email@example.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.
The easiest way to install the plugin is to install it as a bundle:
- Get and install pathogen.vim. You can skip this step if you already have it installed.
- cd ~/.vim/bundle
- git clone git://github.com/aperezdc/vim-templates.git
In order to update the plugin, go to the its bundle directory and use Git to update it:
- cd ~/.vim/bundle/vim-templates
- git pull
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 foo to load the template that would be loaded for file with suffix foo. E.g. from within Vim:
The algorithm to search for templates works like this:
- A file named =template.<suffix> in the current directory. If not found, goto (2).
- Go up a directory and goto (1), if not possible, goto (3).
- Try to use the template.<suffix> file supplied with the plugin.
The following variables will be expanded in templates:
- %DAY%, %YEAR%, %MONTH%
- Numerical day of the month, year and month.
- Date in YYYY-mm-dd format
- Time in HH:MM format
- Full date (date + time), in YYYY-mm-dd HH:MM format.
- File name, without extension.
- File name, with extension.
- File extension.
- Current user's e-mail address. May be overriden by defining g:email.
- Current logged-in user name. May be overriden by defining g:username.
- Host name.
- A string with alphanumeric characters and underscores, suitable for use in proprocessor guards for C/C++/Objective-C header files.
- Expands to nothing, but ensures that the cursor will be placed in its position after expanding the template.