Xptemplate
Code snippets engine for Vim, with snippets library. XPTemplate let you write codes in a smooth, quick and comfortable way.
Install / Use
/learn @drmingdrmer/XptemplateREADME
Table of Contents generated with DocToc
- XPTemplate
- FAQ
- Trouble Shooting. Why not work?
- What else does xptemlate required to work
- How to install
- Customizing snippet loading
- How to reload snippets, after I changes snippet definition files(*.xpt.vim)?
- Do NOT like spaces in auto-completed brackets/braces
- I need spaces in brackets/braces only for this language, not that
- I do not want XPTemplate to auto-complete braces
- Adjust space and line-break
- Adjust format style of c functions, such as
main() - Supertab support
- With popup menu opened,
<TAB>doesn't trigger Snippe - Set up personal info. XPTemplate complains: "author is not set .."
- Browse snippets: Pop up menu, Drop down list
- Extend XPTemplate. Write new snippets
- Example of repetition snippet.
- Define repetition trigger place holder
- Known Issues
XPTemplate
Code snippets engine for Vim, And snippets library. Write codes in a smooth, quick and comfortable way. [xptemplate-vim.org][xpt-vim]
<iframe src="http://ghbtns.com/github-btn.html?user=drmingdrmer&repo=xptemplate&type=watch&count=true" allowtransparency="true" frameborder="0" scrolling="0" width="110" height="20"></iframe>Usage
>vim xpt.c
for<C-\>
generates:
for (i = 0; i < len; ++i){
/* cursor */
}
Press <tab>,<tab>.. to navigate through "i", "0", "len" and finally stop at "/* cursor */"
Browse and basic usage

C skeleton

C macro

C for loop and wrapper

C if-else-else

Python option argument

Python def and def in class

Python inline completion

Python try-except can be a wrapper

Python quickly add snippet

Video tutorial
Tutorial by Derek Wyatt : http://vimeo.com/4449258
Stay up-to-date
There are two major branches: "master" and "dev".
- "master" is compacted, logging-removed version. Always use branch "master" unless you know what you are doing.
- "dev" is for development, that it contains debug statements thus it is a bit slow.
Before 2014-06-01, The two major branches are: "master" and "dist":
- "master" is for developing purpose.
- "dist" is for end user.
About branches
-
Branch
masteris the branch for end user. -
Branch
devis for doing further developing on top of XPTemplate. -
Branches that starts with
f.are feature branches for different sub system of XPTemplate. -
Branches that starts with
fd.are feature breanches that has not yet been merged intodevandmaster, which are NOT considered stable. -
Branches that starts with
snp.are snippet branches.
Features
- Live update while typing.
- Navigate forward and backward with
<Tab>and<S-Tab>. - Support embedded language like JAVASCRIPT in HTML. Or HTML in PHP.
- Wrapper snippet.
- Inclusion.
- Generate dynamic content with variables/functions.
- code style customization: line break before "{".
- Filters.
FAQ
Trouble Shooting. Why not work?
First of all, Enter VIM.
-
Check setting "compatible". In VIM, type:
:set compatible?Make sure you get "nocompatible". Or you need the following statement in your .vimrc:
set nocompatible -
Check setting "filetype". In VIM, type:
:filetypeMake sure you get "filetype detection:ON plugin:ON ...". Or you need the following statement in you .vimrc:
filetype plugin on -
Check if XPTemplate is loaded. In VIM, type:
:scriptnamesYou will get a list of scripts VIM has loaded. There should be some files with name started with "xpt", like this:
97: /data/.../dist/plugin/xptemplate.vim 98: /data/.../dist/plugin/xptemplate.conf.vim 99: /data/.../dist/plugin/xptemplate.util.vimIf not, you should check if you have XPTemplate installed correctly.
You should see files with name started with "xpt.." in folder ~/.vim/ (Unix-like OS) or in $VIMH/vimfiles/ (Windows). Like this:
|-- plugin ... | |-- xpopup.vim | |-- xpreplace.vim | |-- xptemplate.conf.vim ...Reference:
:help 'runtimepath' -
Check key binding. Make sure you have a clear environment: none of XPTemplate settings like "let g:xpt..." in you .vimrc file. In VIM, type:
:imap <C-\>You will get something like this:
i <C-\> * <C-R>=XPTemplateStart(0,{'k':'<C-\++'})<CR>This means your XPTemplate should work well. Or check if some other plugin has conflicting key-binding. If so, solve it by adding the following statement into you .vimrc file to change XPTemplate key-binding:
let g:xptemplate_key = '<Tab>' -
Now type in insert-mode:
Date<C-\>You will get current date.
What else does xptemlate required to work
VIM and nothing else!
XPTemplate is implemented purely with VIM script. Nothing else(like python) is required but a single VIM( at least 7.2 ).
XPTemplate works also in VIM 7.0 too. But it's no as good as in VIM 7.2.
How to install
Copy all folders in to your ~/.vim folder(on unix-like OS)
Or add path to XPTemplate to VIM setting 'runtimepath'.
Customizing snippet loading
To load your own snippets and NOT to load snippets supplied by XPTemplate,
add this line to your .vimrc:
let g:xptemplate_lib_filter = '/my_snippets/'
Snippets from folder ~/xpt/ that does not match g:xptemplate_lib_filter
will not be loaded.
~/xpt/ftplugin/c/c.xpt.vim
...
~/my_snippets/ftplugin/c/c.xpt.vim
...
How to reload snippets, after I changes snippet definition files(*.xpt.vim)?
:XPTreload
Do NOT like spaces in auto-completed brackets/braces
Spaces inside auto-completed brackets are controlled by XPTemplate variable $SParg.
The Simplest way to disable spaces globally is to add following statements to .vimrc:
let g:xptemplate_vars = "SParg="
With this setting, "(" results in "()" but not "( )" by default.
I need spaces in brackets/braces only for this language, not that
Assume you do need spaces in brackets for java( that you want "()" but not "( )").
Create a snippet file to defines your own preference:
.vim/ftplugin/java/mine.xpt.vim
Add add following contents to this file:
XPTemplate priority=personal
XPTvar $SParg ''
I do not want XPTemplate to auto-complete braces
I want XPTemplate to complete (, [, but not {.
Add this to .vimrc:
let g:xptemplate_brace_complete = '(['
Or you may just want to disable brackets complete:
let g:xptemplate_brace_complete = ''
Adjust space and line-break
Spaces and line-breaks are defined by some variable. Instead of rewrite snippet in your own coding style, modifying these variable is the easiest way.
For example by default "for" loop snippet in C lang is like:
for ( i = 0; i < len; i++ ) {
/* cursor */
}
As snippet "for" defined as:
for`$SPcmd^(`$SParg^`$FOR_SCOPE^`$VAR_PRE`i^`$SPop^=`$SPop^`0^; `i^`$SPop^<`$SPop^`len^; `i^++`$SParg^)`$BRloop^{
`cursor^
}
If you want to remove space after "for" and create a line-break before "{":
for( i = 0; i < len; i++ )
{
/* cursor */
}
Just add two variables into your .vimrc file:
let g:xptemplate_vars = "SPcmd=&BRloop=\n"
Adjust format style of c functions, such as main()
Default c function indent is like this:
int
main( int argc, char **argv )
{
return 0;
}
This is controlled by variable $BRfun, if you prefer the single line style:
int main( int argc, char **argv ) {
return 0;
}
Add variable into your .vimrc file, to make ALL function snippets to use single line style:
let g:xptemplate_vars = "BRfun= "
Or redefine $BRfun in higher priority sni
