templates.vim : Load filetype templates for new files
| script karma |
Rating 178/77,
Downloaded by 3465
|
Comments, bugs, improvements
|
Vim wiki
|
| created by |
| Aristotle Pagaltzis |
| |
| script type |
| utility |
| |
| description |
templates.vim lets you use filetype-dependent templates for new files, using a simple but effective mechanism.
It is, in various ways, a more sophisticated approach to the same problem that vimscript #1160 addresses, but doesn't try to do quite as much.
Usage is simple: when you start with a fresh buffer, setting a filetype on it will load the corresponding template. To test it, open Vim and issue
:set ft=html
One new command has been added for convenience: it is called :New and takes exactly one argument. It will open a new empty window and set the filetype for it to the argument given.
Templates are kept in “.vim/templates”. The template filename must be equal to the filetype. So when you set the filetype of an empty buffer to “html”, “.vim/templates/html” will be loaded. It's that simple.
In the templates, you can use a cursorline to specify a position for the cursor after loading the template. Such a cursorline works much like a modeline: the word “cursor:” must appear, followed by one or two numbers and opionally the word “del”, all separated by whitespace. The first number specifies the line the cursor will be placed in. The second, if present, specifies a column. The optional word “del” directs the script to remove the cursorline at load time. Take a look at the templates supplied in the package, it should be fairly self-explanatory. |
| |
| install details |
This script uses a new distribution format: it's a self-extracting vim archive. Simply save it somewhere and source it from Vim: it will automatically extract the contained files. It may not yet work well on Windows (creating directories is not implemented, in particular), but I will fix that soon.
Some sample templates are included.
(I plan to write and release another script that creates such archives in the near future. Look for it here on vim.org. In the meantime, you can probably figure out how it works by looking at the source — it's really quite unremarkable.) |
| |
script versions (upload new version)
Click on the package to download.
ip used for rating: 107.22.127.92
|