adding new stuff

This commit is contained in:
ViktorBarzin 2017-07-09 00:22:01 +03:00
parent f84d7183aa
commit 9ef8a96f9a
1580 changed files with 0 additions and 0 deletions

View file

@ -0,0 +1,173 @@
<Plug>XPTrawKey xptemplate.txt /*<Plug>XPTrawKey*
Build() xpt/snippet-function.txt /*Build()*
BuildSnippet() xpt/snippet-function.txt /*BuildSnippet()*
C() xpt-function.txt /*C()*
E({expr}) xpt-function.txt /*E({expr})*
Echo() xpt/snippet-function.txt /*Echo()*
Include: xpt.snippet.syn.txt /*Include:*
N() xpt-function.txt /*N()*
R({name}) xpt-function.txt /*R({name})*
S() xpt-function.txt /*S()*
S({expr},{pat},{sub},{flags}) xpt-function.txt /*S({expr},{pat},{sub},{flags})*
SV() xpt-function.txt /*SV()*
V() xpt-function.txt /*V()*
XPTcurrentPH xptemplate.txt /*XPTcurrentPH*
XPTembed xpt.snippet.syn.txt /*XPTembed*
XPTemplate xptemplate.txt /*XPTemplate*
XPTemplate() xpt.api.txt /*XPTemplate()*
XPTemplateMark() xpt.api.txt /*XPTemplateMark()*
XPTemplatePriority() xpt.api.txt /*XPTemplatePriority()*
XPTemplateTrigger() xpt.api.txt /*XPTemplateTrigger()*
XPTfollowingPH xptemplate.txt /*XPTfollowingPH*
XPTfuncs() xpt.api.txt /*XPTfuncs()*
XPTinclude xpt.snippet.syn.txt /*XPTinclude*
XPTinfo() xpt.api.txt /*XPTinfo()*
XPTinfoStr([fmt,[sep]]) xpt.api.txt /*XPTinfoStr([fmt,[sep]])*
XPTnextItem xptemplate.txt /*XPTnextItem*
XPTtgr() xpt.api.txt /*XPTtgr()*
XPTvar xpt.snippet.syn.txt /*XPTvar*
^ xpt.snippet.syn.txt /*^*
` xpt.snippet.syn.txt /*`*
`...^ xptemplate.txt /*`...^*
`::^ xpt.snippet.syn.txt /*`::^*
``` xpt.snippet.syn.txt /*```*
`cursor^ xpt.snippet.syn.txt /*`cursor^*
g:XPTaddBundle() xpt.api.txt /*g:XPTaddBundle()*
g:xptemplate_always_show_pum xpt/option.txt /*g:xptemplate_always_show_pum*
g:xptemplate_brace_complete xpt/option.txt /*g:xptemplate_brace_complete*
g:xptemplate_break_undo xpt/option.txt /*g:xptemplate_break_undo*
g:xptemplate_bundle xpt/option.txt /*g:xptemplate_bundle*
g:xptemplate_close_pum xpt/option.txt /*g:xptemplate_close_pum*
g:xptemplate_cwd_snippet xpt/option.txt /*g:xptemplate_cwd_snippet*
g:xptemplate_debug_log xpt/option.txt /*g:xptemplate_debug_log*
g:xptemplate_fallback xptemplate.txt /*g:xptemplate_fallback*
g:xptemplate_goback xptemplate.txt /*g:xptemplate_goback*
g:xptemplate_highlight xpt/option.txt /*g:xptemplate_highlight*
g:xptemplate_highlight_nested xpt/option.txt /*g:xptemplate_highlight_nested*
g:xptemplate_hook_before_cr xpt/option.txt /*g:xptemplate_hook_before_cr*
g:xptemplate_key xptemplate.txt /*g:xptemplate_key*
g:xptemplate_key_force_pum xptemplate.txt /*g:xptemplate_key_force_pum*
g:xptemplate_key_pum_only xptemplate.txt /*g:xptemplate_key_pum_only*
g:xptemplate_lib_filter xpt/option.txt /*g:xptemplate_lib_filter*
g:xptemplate_minimal_prefix xpt/option.txt /*g:xptemplate_minimal_prefix*
g:xptemplate_move_even_with_pum xpt/option.txt /*g:xptemplate_move_even_with_pum*
g:xptemplate_nav_cancel xptemplate.txt /*g:xptemplate_nav_cancel*
g:xptemplate_nav_next xptemplate.txt /*g:xptemplate_nav_next*
g:xptemplate_nav_prev xptemplate.txt /*g:xptemplate_nav_prev*
g:xptemplate_ph_pum_accept_empty xpt/option.txt /*g:xptemplate_ph_pum_accept_empty*
g:xptemplate_pum_quick_back xpt/option.txt /*g:xptemplate_pum_quick_back*
g:xptemplate_pum_tab_nav xpt/option.txt /*g:xptemplate_pum_tab_nav*
g:xptemplate_snippet_folders xpt/option.txt /*g:xptemplate_snippet_folders*
g:xptemplate_strict xpt/option.txt /*g:xptemplate_strict*
g:xptemplate_strip_left xpt/option.txt /*g:xptemplate_strip_left*
g:xptemplate_to_right xptemplate.txt /*g:xptemplate_to_right*
g:xptemplate_vars xpt/option.txt /*g:xptemplate_vars*
i_<C-\> xptemplate.txt /*i_<C-\\>*
i_<C-g> xptemplate.txt /*i_<C-g>*
i_<C-r><C-r><C-\> xptemplate.txt /*i_<C-r><C-r><C-\\>*
i_<S-tab> xptemplate.txt /*i_<S-tab>*
i_<tab> xptemplate.txt /*i_<tab>*
n_<C-g> xptemplate.txt /*n_<C-g>*
s_<C-\> xptemplate.txt /*s_<C-\\>*
s_<C-l> xptemplate.txt /*s_<C-l>*
s_<CR> xptemplate.txt /*s_<CR>*
s_<S-tab> xptemplate.txt /*s_<S-tab>*
s_<tab> xptemplate.txt /*s_<tab>*
self.renderContext xpt.api.txt /*self.renderContext*
v_<C-\> xptemplate.txt /*v_<C-\\>*
xpt xptemplate.txt /*xpt*
xpt-$ xpt.snippet.syn.txt /*xpt-$*
xpt-... xptemplate.txt /*xpt-...*
xpt-``` xpt.snippet.syn.txt /*xpt-```*
xpt-api xpt.api.txt /*xpt-api*
xpt-bundle xptemplate.txt /*xpt-bundle*
xpt-context xptemplate.txt /*xpt-context*
xpt-customize xptemplate.txt /*xpt-customize*
xpt-customize-highlight xptemplate.txt /*xpt-customize-highlight*
xpt-customize-variable xptemplate.txt /*xpt-customize-variable*
xpt-customize-variable-datetime xptemplate.txt /*xpt-customize-variable-datetime*
xpt-customize-variable-format xptemplate.txt /*xpt-customize-variable-format*
xpt-customize-variable-space xptemplate.txt /*xpt-customize-variable-space*
xpt-feature xptemplate.txt /*xpt-feature*
xpt-install xptemplate.txt /*xpt-install*
xpt-key-bind xptemplate.txt /*xpt-key-bind*
xpt-key-clear xptemplate.txt /*xpt-key-clear*
xpt-key-goback xptemplate.txt /*xpt-key-goback*
xpt-key-goto-right xptemplate.txt /*xpt-key-goto-right*
xpt-key-navigate xptemplate.txt /*xpt-key-navigate*
xpt-key-pum xptemplate.txt /*xpt-key-pum*
xpt-key-trigger xptemplate.txt /*xpt-key-trigger*
xpt-key-visual xptemplate.txt /*xpt-key-visual*
xpt-mixed xpt.snippet.syn.txt /*xpt-mixed*
xpt-name-matching xptemplate.txt /*xpt-name-matching*
xpt-nested xptemplate.txt /*xpt-nested*
xpt-option xpt/option.txt /*xpt-option*
xpt-personal-folder xptemplate.txt /*xpt-personal-folder*
xpt-personal-var xpt/option.txt /*xpt-personal-var*
xpt-placeholder-cursor xpt.snippet.syn.txt /*xpt-placeholder-cursor*
xpt-placeholder-default-value xpt.snippet.syn.txt /*xpt-placeholder-default-value*
xpt-placeholder-edge xpt.snippet.syn.txt /*xpt-placeholder-edge*
xpt-placeholder-left-mark xpt.snippet.syn.txt /*xpt-placeholder-left-mark*
xpt-placeholder-mark xpt.snippet.syn.txt /*xpt-placeholder-mark*
xpt-placeholder-ontime-filter xpt.snippet.syn.txt /*xpt-placeholder-ontime-filter*
xpt-placeholder-optional-ph xpt.snippet.syn.txt /*xpt-placeholder-optional-ph*
xpt-placeholder-post-filter xpt.snippet.syn.txt /*xpt-placeholder-post-filter*
xpt-placeholder-right-mark xpt.snippet.syn.txt /*xpt-placeholder-right-mark*
xpt-placeholder-special xpt.snippet.syn.txt /*xpt-placeholder-special*
xpt-popup xptemplate.txt /*xpt-popup*
xpt-priority-format xpt.snippet.syn.txt /*xpt-priority-format*
xpt-priority-value xpt.snippet.syn.txt /*xpt-priority-value*
xpt-repetition xptemplate.txt /*xpt-repetition*
xpt-snippet xpt.snippet.syn.txt /*xpt-snippet*
xpt-snippet-ComeFirst xpt.snippet.syn.txt /*xpt-snippet-ComeFirst*
xpt-snippet-ComeLast xpt.snippet.syn.txt /*xpt-snippet-ComeLast*
xpt-snippet-XPTinclude xpt.snippet.syn.txt /*xpt-snippet-XPTinclude*
xpt-snippet-XSET xpt.snippet.syn.txt /*xpt-snippet-XSET*
xpt-snippet-XSETm xpt.snippet.syn.txt /*xpt-snippet-XSETm*
xpt-snippet-abbr xpt.snippet.syn.txt /*xpt-snippet-abbr*
xpt-snippet-alias xpt.snippet.syn.txt /*xpt-snippet-alias*
xpt-snippet-body xpt.snippet.syn.txt /*xpt-snippet-body*
xpt-snippet-default-post-filter xpt.snippet.syn.txt /*xpt-snippet-default-post-filter*
xpt-snippet-default-value xpt.snippet.syn.txt /*xpt-snippet-default-value*
xpt-snippet-embed xpt.snippet.syn.txt /*xpt-snippet-embed*
xpt-snippet-expandable xpt.snippet.syn.txt /*xpt-snippet-expandable*
xpt-snippet-expression xpt.snippet.syn.txt /*xpt-snippet-expression*
xpt-snippet-function xpt/snippet-function.txt /*xpt-snippet-function*
xpt-snippet-function-ctx xpt.api.txt /*xpt-snippet-function-ctx*
xpt-snippet-header xpt.snippet.syn.txt /*xpt-snippet-header*
xpt-snippet-hidden xpt.snippet.syn.txt /*xpt-snippet-hidden*
xpt-snippet-hint xpt.snippet.syn.txt /*xpt-snippet-hint*
xpt-snippet-include xpt.snippet.syn.txt /*xpt-snippet-include*
xpt-snippet-instant-value xpt.snippet.syn.txt /*xpt-snippet-instant-value*
xpt-snippet-item xpt.snippet.syn.txt /*xpt-snippet-item*
xpt-snippet-keyword xpt.snippet.syn.txt /*xpt-snippet-keyword*
xpt-snippet-leading-placeholder xpt.snippet.syn.txt /*xpt-snippet-leading-placeholder*
xpt-snippet-mark xpt.snippet.syn.txt /*xpt-snippet-mark*
xpt-snippet-name xpt.snippet.syn.txt /*xpt-snippet-name*
xpt-snippet-name-matching-rule xpt.snippet.syn.txt /*xpt-snippet-name-matching-rule*
xpt-snippet-placeholder xpt.snippet.syn.txt /*xpt-snippet-placeholder*
xpt-snippet-post-filter xpt.snippet.syn.txt /*xpt-snippet-post-filter*
xpt-snippet-postQuoter xpt.snippet.syn.txt /*xpt-snippet-postQuoter*
xpt-snippet-preset-value xpt.snippet.syn.txt /*xpt-snippet-preset-value*
xpt-snippet-priority xpt.snippet.syn.txt /*xpt-snippet-priority*
xpt-snippet-repetition xpt.snippet.syn.txt /*xpt-snippet-repetition*
xpt-snippet-sample xpt.snippet.syn.txt /*xpt-snippet-sample*
xpt-snippet-setting xpt.snippet.syn.txt /*xpt-snippet-setting*
xpt-snippet-synonym xpt.snippet.syn.txt /*xpt-snippet-synonym*
xpt-snippet-syntax xpt.snippet.syn.txt /*xpt-snippet-syntax*
xpt-snippet-tutorial xpt.snippet.tutor.txt /*xpt-snippet-tutorial*
xpt-snippet-variable xpt.snippet.syn.txt /*xpt-snippet-variable*
xpt-snippet-wrap xpt.snippet.syn.txt /*xpt-snippet-wrap*
xpt-snippet-wraponly xpt.snippet.syn.txt /*xpt-snippet-wraponly*
xpt-substitute xpt-function.txt /*xpt-substitute*
xpt-tips xptemplate.txt /*xpt-tips*
xpt-tutor-define-snippet xpt.snippet.tutor.txt /*xpt-tutor-define-snippet*
xpt-tutor-snippet-file xpt.snippet.tutor.txt /*xpt-tutor-snippet-file*
xpt-usage xptemplate.txt /*xpt-usage*
xpt-with-supertab xptemplate.txt /*xpt-with-supertab*
xpt-wrapper-snippet xptemplate.txt /*xpt-wrapper-snippet*
xpt-write-common-snippet xptemplate.txt /*xpt-write-common-snippet*
xpt-write-lang-snippet xptemplate.txt /*xpt-write-lang-snippet*
xpt-write-snippet xptemplate.txt /*xpt-write-snippet*
xpt-{} xpt.snippet.syn.txt /*xpt-{}*
xptemplate xptemplate.txt /*xptemplate*

View file

@ -0,0 +1,35 @@
*S()* *xpt-substitute*
S({pattern},{replace},[{flag}])
Substitute typed content with pattern and replace. Just like
|substitute()|.
*C()*
C()
Get function context, see |xpt-snippet-function-ctx|.
*E({expr})*
E({expr})
Equals to |expand()|.
*N()*
N()
Current edited item name. Valid only to |xpt-snippet-post-filter|.
*V()*
V()
Current typed text. Valid only to |xpt-snippet-post-filter|.
*R({name})*
R({name})
Reference to history item. Get value by name.
*S({expr},{pat},{sub},{flags})*
S({expr},{pat},{sub},{flags})
Equals to |substitute()|.
*SV()*
SV()
Equals to S(V(),{pat},{sub},{flag}).
" vim:tw=78:ts=8:sw=8:sts=8:noet:ft=help:norl:

View file

@ -0,0 +1,153 @@
*xpt-api*
This file describes the public functions provided by XPTemplate which
can be used in snippets.
*g:XPTaddBundle()*
g:XPTaddBundle({filetype}, {bundle})
Load a bundle. {filetype} is the current buffer file type in most
case. And {bundle} is the file name which supplies the bundle.
For example loading jquery bundle for HTML buffer(or JAVASCRIPT buffer): >
call g:XPTaddBundle('javascript', 'jquery')
<
*XPTfuncs()*
g:XPTfuncs()
g:XPTfuncs() returns a |Dictionary| container of functions which can
be used in templates in the current buffer. The normal usage of
g:XPTfuncs() to define a template function is : >
let s:f = g:XPTfuncs()
fun! s:f.date() dict
return strftime("%Y %b %d")
endfunction
<
Now you can use functions and variables in the template : >
call XPTemplate("filehead", [
\'/**--------------------/// `sum^ \\\----------------------',
\' *',
\' * @version : `1.0^',
\' * @since : `date()^',
\' * @author : `$author^ | `$email^',
\' * @copyright `.com.cn^ ',
\' * @TODO : ',
\' * ',
\' *---------------------\\\ `sum^ ///----------------------*/',
\''])
<
*XPTemplate()*
XPTemplate({name} [, {context}], {template})
XPTemplate defines a template for the current buffer. It takes 2 or 3
parameters:
{name} is a string representing the key to trigger this template.
{context} can be omitted or an |Dictionary| which defines where this
template can be triggered. For now only "syn" is supported.
{template} is a string or |List|. |List| will be joined with "\n"
forming a template string. This saves you adding "\n" to each line.
*XPTemplateMark()*
XPTemplateMark({leftmark}, {rightmark})
XPTemplateMark defines which characters are used as item quoter in the
current buffer. See |xpt-placeholder-mark|.
NOTE this function affects only the current script and current buffer.
*XPTemplatePriority()*
XPTemplatePriority({priority})
XPTemplatePriority sets the default priority for the current *.xpt.vim
script and current buffer. See |xpt-priority-value|.
NOTE this function affects only the current script and current buffer.
*self.renderContext* *xpt-snippet-function-ctx*
The template context can be accessed from within an
|xpt-snippet-function|. For example in the "item-reference" function:
>
fun! s:f.R(name)
let ctx = self.renderContext
if has_key(ctx.namedStep, a:name)
return ctx.namedStep[a:name]
endif
return a:ctx.name
endfunction
<
*XPTtgr()*
XPTtgr( {snippetName} [, {option} ] )
Trigger an snippet of name {snippetName} in insert mode. This function
returns and |i_CTRL-R_=| expression. You should always use this
function following "<C-R>=".
As Example, the following two command defines auto-complete brace: >
call XPTemplate('brace', '{`^}')
inoremap { <C-r>=XPTtgr('brace')<CR>
<
After executing these 2 command, a "{" key-stroke produces a pair of
braces: "{}" and cursor left between them.
Table below lists all {option} keys: >
{option}.syn Regular expression defines pattern what syntax
name must match for snippet to trigger.
{option}.nosyn Regular expression defines pattern what syntax
name must NOT match for snippet to trigger.
{option}.literal Snippet can only be triggered in string or
comment. Same as
{option}.syn='\V\cstring\|comment'.
{option}.noliteral Snippet can only be triggered outside of
string or comment. Same as
{option}.nosyn='\V\cstring\|comment'.
{option}.k What should be produced if condition is not
satisfied to trigger snippet.
<
*XPTemplateTrigger()*
XPTemplateTrigger( {snippetName} [, {option} ] )
Deprecated.
Same as |XPTtgr()|.
*XPTinfo()*
XPTinfo()
Return 0 if no snippet in processing on screen.
Return an array representing snippets stack on screen in following
format:
>
[ {
"$snipname" : "<snippet-name>",
"$phname" : "<placeholder-name>"
}, ... ]
<
In outer-to-inner order
*XPTinfoStr([fmt,[sep]])*
XPTinfoStr([fmt,[sep]])
Return data of |XPTinfo()| in string.
Argument "fmt": format for rendering infomation of each nested snippet
in stack. Default value is "$snipname.$phname".
Argument "sep": string as a separator. Default value is " > ".
By default XPTinfoStr() returns: >
"<snip-a>.<ph-x> > <snip-inside-a>.<ph-y>..."
<
Example: Adding this function to 'statusline' as a indicator when
working with deeply nested snippets: >
let &statusline .= '%{XPTinfoStr()}'
<
" vim:tw=78:ts=8:sw=8:sts=8:noet:ft=help:norl:

View file

@ -0,0 +1,923 @@
*xpt-snippet-syntax*
XPT Snippet Syntax
by drdr.xp
drdr.xp@gmail.com
==============================================================================
Content table:
|xpt-snippet-sample|
|xpt-snippet-header|
|xpt-snippet-priority|
|xpt-priority-value|
|xpt-priority-format|
|xpt-snippet-keyword|
|xpt-snippet-mark|
|xpt-snippet-variable|
|xpt-snippet-function|
|xpt-snippet-XPTinclude|
|xpt-snippet-embed|
|xpt-snippet|
|xpt-snippet-name|
|xpt-snippet-setting|
|xpt-snippet-hint|
|xpt-snippet-hidden|
|xpt-snippet-alias|
|xpt-snippet-synonym|
|xpt-snippet-wrap|
|xpt-snippet-wraponly|
|xpt-snippet-abbr|
|xpt-snippet-body|
|xpt-snippet-include|
|xpt-snippet-XSET|
|xpt-snippet-XSETm|
|xpt-snippet-ComeFirst|
|xpt-snippet-ComeLast|
|xpt-snippet-postQuoter|
|xpt-snippet-item|
|xpt-snippet-placeholder|
|xpt-placeholder-mark|
|xpt-placeholder-left-mark| |`|
|xpt-placeholder-right-mark| |^|
|xpt-placeholder-edge|
|xpt-snippet-leading-placeholder|
|xpt-placeholder-special|
|xpt-placeholder-cursor|
|xpt-snippet-expression|
|xpt-snippet-instant-value|
|xpt-snippet-preset-value|
|xpt-snippet-default-value|
|xpt-snippet-post-filter|
|xpt-snippet-default-post-filter|
|xpt-placeholder-optional-ph|
|xpt-placeholder-default-value|
|xpt-placeholder-post-filter|
|xpt-placeholder-ontime-filter|
|xpt-snippet-expandable|
|xpt-snippet-repetition|
*xpt-snippet-sample*
A snippet file looks like this : >
XPTemplate priority=lang keyword=$ | |xpt-snippet-header|
let s:f = XPTfuncs() | |xpt-snippet-function|
XPTvar $TRUE true | |xpt-snippet-variable|
XPTvar $FALSE false |
XPTvar $NULL null |
XPTvar $UNDEFINED undefined |
|
XPTvar $CL /* |
XPTvar $CM * |
XPTvar $CR */ |
|
XPTinclude | |xpt-snippet-XPTinclude|
\ _common/common |
\ _comment/doubleSign |
\ _condition/c.like |
fun! s:f.js_filename() | |xpt-snippet-function|
return expand( "%" ) |
endfunction |
XPT cmt hint=/**\ @auth...\ */ | |xpt-snippet|
XSET author=$author | |xpt-snippet-XSET|
XSET email=$email | |xpt-snippet-XSET|
/** |\
* @author : `author^ | `email^ | \
* @description | +|xpt-snippet-body|
* `cursor^ | /
* @return {`Object^} `desc^ |/
*/
XPT for hint=for\ (var..;..;++)
for ( i=0; i<`len^; ++i ) { `cursor^ }
<
*xpt-snippet-header*
Each snippet file starts with a XPTemplate declaration for
snippet-scope setting, duplication load check, etc.
Format : >
XPTemplate [priority=lang] [keyword=#] [mark=`^]
<
There are 3 optional settings for 'XPTemplate' :
*xpt-snippet-priority*
Priority affects |xpt-snippet| and |xpt-snippet-variable|;
|xpt-snippet-function| is defined directly, so it isn't controlled by
|xpt-snippet-priority|. Snippets with a lower |xpt-snippet-priority|
override higher ones. Format : >
XPTemplate priority=<priority-value>
< See |xpt-priority-value|.
*xpt-priority-value*
Snippets are defined with a certain priority. One buffer might load
snippets with the same name. Only the snippet with the lowest priority
is used, others are ignored.
Priorities can be in the range from 0 to +oo. 0 is the highest
priority. Some predefined symbols stand for numeric priority
values : >
all : 64
spec : 48
like : 32
lang : 16
sub : 8
personal : 0
< Default priority is "lang" or 16.
You can set priority for each snippet by using |xpt-priority-format|.
Or set priority for all templates in the current file with
|XPTemplatePriority()|.
*xpt-priority-format*
Priority setting format : "priority[+/-[offset]]".
Following formats are all valid : >
3 3
lang 16
like+4 36 // like=32
all- 63 // all=64
all-1 63 // all=64
<
*xpt-snippet-keyword*
|xpt-snippet-keyword| defines what characters other than word chars
can be used as |xpt-snippet-name|.
You do not need to specify explicitly what char is
xpt-snippet-keyword. It is automatically added when non-word char
presents in snippet name. For example: >
XPT #include <`^.h>
<
After the above snippet loaded, "#" is added.
See also |xpt-snippet-name-matching-rule|.
*xpt-snippet-mark*
To specify which 2 characters are used as |xpt-placeholder-mark|
instead of the default |`| and |^|. Format : >
XPTemplate mark=~^
<
*xpt-$*
*XPTvar*
*xpt-snippet-variable*
|xpt-snippet-variable| can be used in :
|xpt-snippet-instant-value|
|xpt-snippet-preset-value|
|xpt-snippet-default-value|
|xpt-snippet-post-filter|
|xpt-placeholder-ontime-filter|
Format : >
XPTvar $VAR_NAME something
< Or with single quoter : >
XPTvar $VAR_NAME 'something'
< The only difference is that in single quoted strings space can be
freely used. Like this : >
XPTvar $VAR_NAME ' '
< Instead of using the escaped format "\ ".
It's also possible to set a variable to the empty value: >
XPTvar $VAR_NAME ''
<
Another example from C language : >
XPTvar $TRUE 1
< and a snippet defined as : >
XPT while1
while (`$TRUE^) {
`cursor^
}
< will generate : >
while (1) {
`cursor^
}
<
|xpt-snippet-variable| is used widely in XPTemplate, such as comment
definition, format customization, etc.
Personal information variables should be defined by using
|g:xptemplate_vars|. Variables defined with |g:xptemplate_vars|
override variables defined in any snippet files.
NOTE By convention the names of |xpt-snippet-variable| supplied by
XPTemplate start with an upper-case letter. User defined
variable name should start with a lower-case letter.
NOTE Override control of |xpt-snippet-variable| is affected by
|xpt-snippet-priority|.
*XPTinclude*
*xpt-snippet-XPTinclude*
Syntax : >
XPTinclude <folder_name_in_ftplugin>/<filename>
< The <filename> is only the file root, without ".xpt.vim".
XPTinclude can include several snippets at one time.
NOTE do NOT use |:runtime| to include other snippet files. XPTinclude
handles snippet priority, but |:runtime| does NOT.
*XPTembed*
*xpt-snippet-embed*
Syntax : >
XPTembed <folder_name_in_ftplugin>/<filename>
< |XPTembed| acts like |XPTinclude|, except it includes only snippet
files for nested languages, like JavaScript in HTML, or HTML in PHP.
NOTE TODO differences between XPTinclude by example.
*xpt-snippet*
The snippet part starts where the first "XPT ... " presents. Any
content after this command is no longer Vim script, but XPTemplate
snippets.
Each |xpt-snippet| defines one code snippet with the following
syntax : >
XPT <snippetName> [name=value] [name=value] ..
<snippet body>..
..XPT
< 'XPT' is the start of a snippet. '..XPT' is the end of a snippet, it
is optional. If '..XPT' does not present the snippet body ends at the
last non-empty line( but without the last line-break ).
*xpt-snippet-name*
<snippetName> is the name the user has to type to trigger this
snippet. It can only contain word-chars |\w| and
|xpt-snippet-keyword|.
Custom snippets (not provided by XPTemplate) should not start with "_"
by convention as these snippets are used by XPTemplate internally, see
also |xpt-snippet-include|.
*xpt-snippet-name-matching-rule*
When |xpt-key-trigger| key pressed, XPT search for snippet name from
cursor position backwards.
XPT search for longest matching of any snippet prefixes without
breaking any continous words.
For example there are 4 snippets defined: >
XPT a
-a
XPT *
-*
XPT a*
-a*
XPT *a
-*a
< Then what typed and what got is as below: >
a<C-\> -a
*<C-\> -*
a*<C-\> -a*
*a<C-\> -*a
*a<C-\> -*a
xa<C-\> // Nothing matched. Because to match "a"
word "xa" must be broken.
xa*<C-\> xa-*
x*a<C-\> x-*a
x*a*<C-\> x*-a*
<
*xpt-snippet-setting*
The 'name=value' defines snippet settings, including
|xpt-snippet-hint|
|xpt-snippet-hidden|
|xpt-snippet-alias|
*xpt-snippet-hint*
Set the 'menu' entry for the pop up menu; as a short description other
than |xpt-snippet-name|. Like the following C language popup menu : >
| #if #if ... |
| #ifdef #if ... |
| #ifndef #ifndef .. |
<
Syntax to set up hints: >
XPT for hint=for\ (..;..;++)
< Or : >
XPT for " for (..;..;++)
< The quote-hint must be at the end of |xpt-snippet| declaration.
Some characters( space, left quote and "$" ) need to be escaped in
hint text: >
<space> ( $
hint= yes yes yes
" no yes yes
<
With only the 'hint=' way:
space needs to be escaped.
With both these two ways :
"(" needs to be escaped if you do NOT want it to be evaluated
as a function call.
"$" needs to be escaped if you do NOT want it to be evaluated
as variable.
*xpt-snippet-hidden*
Set to 1 to prevent the snippet from being triggered by the user, but
it CAN be triggered from internal API, or included by other snippet.
Syntax: >
XPT for hidden=1 hint=...
< Or: >
XPT for hidden hint=...
<
See |xpt-snippet-include| and |xpt-api|.
*xpt-snippet-alias*
Make the snippet an alias to another snippet. Syntax : >
XPT forin hint=for\ ..\ in\ ..\ ..\ endfor
for `value^ in `list^
`cursor^
endfor
XPT foreach alias=forin hint=for\ ..\ in\ ..\ ..\ endfor
< This makes "forin" and "foreach" the same, but with possible different
settings.
NOTE |xpt-snippet-alias| can be used to create shortcuts.
*xpt-snippet-synonym*
Like |xpt-snippet-alias|, synonym gives a snippet another name.
Syntax : >
XPT snippetName synonym=a|b|c...
< Where a, b and c are all the names of this snippet. For example : >
XPT forin synonym=fin|fi hint=for\ ..\ in\ ..\ ..\ endfor
for `value^ in `list^
`cursor^
endfor
< This makes "forin", "fin" and "fi" the same.
NOTE |xpt-snippet-synonym| can be used to create shortcuts.
*xpt-snippet-wrap*
Wrapper snippets can be triggered in visual mode, place holder marked
as "wrap" is replaced with the text selected in visual mode.
Definition of wrapper snippet has no differences from normal
snippet except it declaring a place holder as wrapping holder. For
example: >
________/---------------------| wrapper declaration
XPT if wrap=job
if (`condition^){
`job^
}
<
Wrapping can be block-wise or line-wise. Wrapper place holder with
|xpt-placeholder-edge| is line-wise, or it is block-wise.
For example: >
XPT comment wrap=what
`/* `what` */^
< This is line-wise wrapper, it will result in: >
/* line1 */
/* line2 */
< But not: >
/* line1
line2 */
<
See also |xpt-wrapper-snippet| and |xpt-snippet-wraponly|.
*xpt-snippet-wraponly*
Normally, wrapper snippet can also be triggered in insert-mode, unless
"wraponly" declared. For example: >
________/------------| wrap only
XPT if wrap=job wraponly
if (`condition^){
`job^
}
<
*xpt-snippet-abbr*
{default:0}
Set to 1 to create |abbreviations| for this snippet.
Example: >
____/------------------------| create abbr
XPT if abbr
if ( ) { }
< Snippet defined as above will be triggered by typing "if<space>" or
"if<C-]>".
*xpt-snippet-body*
<snippet body> is all the OTHER text except the first line : >
XPT for hint=for\ (..;..;++)
for (`i^ = `0^; `i^ < `len^; ++`i^) { |
`cursor^ | snippet body
} |
< |xpt-snippet-body| contains snippet text and :
|xpt-snippet-XSET|
|xpt-snippet-XSETm|
Snippet with XSET command : >
XPT printf hint=printf\(...)
XSET elts=c_printfElts( R( 'pattern' ) )
printf( "`pattern^"`elts^ )
< NOTE XPTemplate use 4-spaces indent. No table-char indent is
allowed in snippet file.
NOTE XSET/XSETm commands can be placed anywhere inside a snippet.
*`::^* *Include:* *xpt-snippet-include*
`:<snipname>:^ Simple Include without "cursor".
`Include:<snipname>^ Include with "cursor" place holder.
`:<snipname>():^ Simple inclusion with parameter.
`Include:<snipname>()^ Inclusion with parameter.
Snippet can include another snippet, through inclusion place holder : >
`Include:snippetName^
< When inclusion occurs, |xpt-snippet-post-filter|,
|xpt-snippet-default-value| and |xpt-snippet-preset-value| is imported
too, if it does not override.
Short inclusion format : >
`:snippetName:^
< Only two ":" around snippet name are needed.
NOTE The only difference between "Include:" and "::" is "Include:"
keeps "cursor" place holder but "::" does not.
Take "if" snippet in file "_condition/c.like.xpt.vim" for example(
snippets are simplified for reading ): >
XPT _if hidden
if ( `condition^ ) {
`job^
}
XPT if hint=if\ (..)\ {..}\ else...
`:_if:^` `else...{{^ `Include:else^`}}^
< The real "if" includes the "_if" and "else" snippets.
NOTE Inclusion is literal, so that snippets with different
|xpt-snippet-mark| can not include each other.
NOTE By convention snippets of name started with "_" are internal
snippets. Normally these snippets are set with
|xpt-snippet-hidden| flag on and used for inclusion only.
Parameters of Inclusion:
Inclusion can have parameters passed to included snippet. Parameters
are name-value pairs. Names are placeholder name. Name-Values presents
in form of |Dictionary|:
`:<snipname>( { '<phname>' : '<new_phname>', ... } ):^
Place holders in sub-snippet presents in parameter are replaced.
*xpt-snippet-XSET*
In |xpt-snippet-body| XSET commands can be used anywhere to set :
|xpt-snippet-preset-value|
|xpt-snippet-default-value|
|xpt-snippet-post-filter|
XSET syntax to set |xpt-snippet-preset-value|: >
XSET itemname|pre=<expression>
< XSET syntax to set |xpt-snippet-default-value|: >
XSET itemname|def=<expression>
< or : >
XSET itemname=<expression>
< XSET syntax to set |xpt-snippet-post-filter|: >
XSET itemname|post=<expression>
< <expression> is |xpt-snippet-expression|. For example : >
XPT #include_user hint=include\ ""
XSET me=fileRoot()
#include "`me^.h"
< Item "me" is set to the file name without extension.
*xpt-snippet-XSETm*
"XSETm" is similar to |xpt-snippet-XSET| except it uses "\n" instead
of "=" in |xpt-snippet-XSET| and ends with "XSETm END". For
example : >
XPT if hint=if\ (..)\ {..}\ else...
if (`condition^) {
`job^
}` `else...^
XSETm else...|post
else {
`cursor^
}
XSETm END
<
*xpt-snippet-ComeFirst*
*xpt-snippet-ComeLast*
Special XSET keys "ComeFirst" and "ComeLast" specify the item render
order. Their value is a list of place holder names separated by space.
For example : >
XPT for hint=for\ (..;..;++)
XSET ComeFirst=0 len
for (`i^ = `0^; `i^ < `len^; ++`i^)`$BRloop^{
`cursor^
}
< So that "0" is focused first, then "len" and then "i".
*xpt-snippet-postQuoter*
The key "postQuoter" is designed to specify quoter do define
|xpt-snippet-expandable|. Default is "{{,}}".
*xpt-snippet-item*
In one snippet a group of |xpt-snippet-placeholder|s with the same
name is an "item". For example : >
XPT for hint=for\ (..;..;++)
for (`i^ = `0^; `i^ < `len^; ++`i^) {
`cursor^
}
< In this snippet there are 4 items : >
i, 0, len, cursor
< Item "i" has 3 |xpt-snippet-placeholder|s, the others have only 1.
*xpt-snippet-placeholder*
A place holder is a segment of a snippet which can be changed by the
user. It's tracked by XPTemplate to update the user input of
|xpt-snippet-placeholder|s within the same |xpt-snippet-item|.
The place holders are defined by |xpt-placeholder-mark|, by default
|`| and |^| are used. For example : >
XPT for hint=for\ (..;..;++)
for (`i^ = `0^; `i^ < `len^; ++`i^) {
`cursor^
}
< Sequentially, the place holders in this snippet are : >
i, 0, i, len, i, cursor
<
Note The placeholder can't contain any backslashes (\). If the default
value should contain any items which need to be escaped (like brackets
or you want to use backslashes directly), use the following syntax
(see |xpt-placeholder-default-value| for more information): >
`name^value with \() here^
<
*xpt-placeholder-left-mark* *`*
*xpt-placeholder-right-mark* *^*
*xpt-placeholder-mark*
|xpt-placeholder-mark| are the characters used to define
|xpt-snippet-placeholder|s of a snippet, by default |`| and |^|.
Or the |xpt-placeholder-left-mark| and |xpt-placeholder-right-mark|.
They can be changed locally, for the current snippet file, by
|xpt-snippet-mark|.
*```* *xpt-```* *xpt-placeholder-edge*
Besides |`| and |^|, additional |xpt-placeholder-left-mark|s can be
set inside place holder to add additional information: the edge.
Edge is some text around a place holder that is not selected when the
cursor jumps to this place holder, but it still can be edited. For
example : >
`(`xpt`)^
< This place holder is named "xpt" and the edges are "(" and ")". When
the cursor jumps onto it : >
(xpt)
***------ only xpt is selected
< Edges help with formatting issues.
Place holder can have only a left edge, for example : >
`(`xpt^
<
NOTE only |\_W| characters are acceptable in edges.
*xpt-snippet-leading-placeholder*
In an item one place holder is the leading place holder which accepts
user input. Others are update by XPTemplate automatically.
By default, the first place holder in item is the leading place
holder, or the one with a |xpt-placeholder-edge|. This allows it to
specify which place holder is the edit area.
For example : >
for (`i^ = `0^; `i^ < `len^; ++`i^) {
`cursor^
}
< In item "i", the first "i" before "=" is the leading one. But in this
snippet : >
for (`i^ = `0^; ``i^ < `len^; ++`i^) {
`cursor^
}
< The second "i", with double |`| before "<", is the leading one.
*xpt-placeholder-special*
Special place holders include : |xpt-placeholder-cursor| and
|xpt-snippet-wrap|.
*`cursor^* *xpt-placeholder-cursor*
Sets where cursor the stops after a snippet finished.
The item named "cursor" is a special one. It's always selected at last
and replaced with an empty string. When navigating to the "cursor"
item the snippet is complete.
*xpt-{}* *xpt-mixed* *xpt-snippet-expression*
Expression is a mixture of plain text, |xpt-snippet-variable| and
|xpt-snippet-function|.
Expression is used as the value of
|xpt-snippet-instant-value|
|xpt-snippet-preset-value|
|xpt-snippet-default-value|
|xpt-snippet-post-filter|
|xpt-placeholder-ontime-filter|.
Functions can be |xpt-snippet-function|s defined as member of
|XPTfuncs()| or native Vim functions.
Functions are called as member of rendering context :
|xpt-snippet-function-ctx|.
Functions or variables can be enclosed by "{}" to prevent function or
variable names messing up with the surrounding plain text.
Functions are not evaluated if "()" is escaped : >
S\(S("abc", '.', '\u&'))
< is evaluated to : >
S(ABC)
<
Escaping the '$' stops variable evaluation : >
\$author
< is evaluated to : >
$author
<
Escaping the "{}" : >
\{S("abc", '.', '\u&')}
< is evaluated to : >
{ABC}
< While : >
{S("abc", '.', '\u&')}
< is evaluated to : >
ABC
<
Another example, supposing you are editing a file named
"your_file_name.ext" : >
__{S(E("%:t"),".","\\u&")}__
< is evaluated to : >
__YOUR_FILE_NAME.EXT__
< And : >
this is S($author,".","-&")-
< is evaluated to : >
this is -d-r-d-r-.-x-p-
< See also:
|xpt-snippet-function|
|xpt-snippet-variable|
*xpt-snippet-instant-value*
There is a special case for |xpt-snippet-placeholder| when the place
holder's content is a |xpt-snippet-expression|. In this case the place
holder is evaluated at once, and no more further editing can happen on
this place holder. For example : >
XPT filehead
...
* @since : `strftime("%Y %b %d")^
...
<
*xpt-snippet-preset-value*
Preset values are like |xpt-snippet-default-value| but are applied
earlier. |xpt-snippet-default-value| are applied before the place
holders are focused; preset value are applied just after the snippet
is displayed on the screen.
To define preset values: >
XSET the_name|pre=<expression>
<
*xpt-snippet-default-value*
By default place holders use their name as the default value but you
can choose another text as default value by using : >
XSET the_name|def=<expression>
<
So that before cursor jumps to leading place holder of name
"the_name", the <expression> evaluated and applied to the place
holder.
Example : the "#ind" snippet defined as : >
XPT #ind
XSET me|def=fileRoot()
#include "`me^.h"
< In C language, type "#ind<C-\>" you get : >
#include "current_file_name.h"
<
NOTE : if default value expression contains only plain string and
|xpt-snippet-variable|, it is used as |xpt-snippet-preset-value|, too;
for better looking without any side-effect.
*xpt-snippet-post-filter*
Post filters are executed after the user presses <Tab> and change the
typed text. To define a post filter use : >
XSET the_name|post=<expression>
< Or use |xpt-snippet-postQuoter| : >
XPT enum hint=enum\ {\ ..\ }
enum `name^`$BRstc^{
`elt^;`
`...{{^
`elt^;`
`...^`}}^
}` `var^;
<
Some usually-used post filter functions are defined in
ftplugin/_common/common.xpt.vim.
For example for c language, "#ifndef" snippet is defined as follows : >
XPT #ifndef hint=#ifndef\ ..
XSET symbol=S(fileRoot(),'\.','_','g')
XSET symbol|post=UpperCase(V())
#ifndef `symbol^
# define `symbol^
`cursor^
#endif `$CL^ `symbol^ `$CR^
..XPT
<
When you pressing <tab> from the first item "symbol", typed content are
converted to upper case. Before <tab> pressed : >
#ifndef __gnu__
# define __gnu__
`cursor^
#endif /* __gnu__ */
< After <tab> pressed : >
#ifndef __GNU__
# define __GNU__
`cursor^
#endif /* __GNU__ */
<
*xpt-snippet-default-post-filter*
Place holder with some special has default post filter set. Following
sections discuss them.
Place holders have default place holder defined: >
\V\w\+? EchoIfNoChange('')
<
*xpt-placeholder-optional-ph*
If a place holder name matches pattern '\V\w\+?', "EchoIfNoChange('')"
is assigned as its post filter.
This makes the place holder optional.
For example a snippet defined as below: >
fun(`arg^`, `context?^)
< When you render this snippet, and cursor stays on "context?" : >
fun(arg, context?)
--------
\__ selected
< Pressing <Tab> clears it, and snippet becomes: >
fun(arg)
<
*xpt-placeholder-post-filter*
For each place holder a private post filter can also be set by using
the |^||^| syntax : >
XPT lowerUpper
lower : `text^
upper : `text^UpperCase(V())^^ <---- double "^"
< Press <Tab>, this snippet results in : >
lower : text
upper : TEXT
<
NOTE If both |xpt-snippet-post-filter| and
|xpt-placeholder-post-filter| are set, the place holder filter takes
effect.
*xpt-placeholder-default-value*
*xpt-placeholder-ontime-filter*
For each place holder an ontime filter can be set to filter the text
each time the user types something by using the |^| syntax : >
XPT lowerUpper
lower : `text^
upper : `text^UpperCase(V())^ <--- only one "^"
< Each time the user types something at place holder "text" the second
place holder is updated with the content converted to upper case.
NOTE ontime filter is used as |xpt-placeholder-default-value| for the
leading place holder.
*xpt-snippet-expandable*
Sometimes you want to create an additional piece of snippet other than
the original snippet. For example, add another "else" after an "if"
block. To do this use expandable : >
XPT if
if `cond^
`job^
`else...{{^else
`cursor^
`}}^
endif
< At the place holder "else..." press <Tab> to generate another else
block, the text quoted by {{ and }}. Press to <Cr> to clear "else...".
Another way to define expandable is by using XSET command to define a
post filter: >
XPT if
if (`condition^)`$BRif^{
`job^
}` `else...^
XSETm else...|post
else {
`cursor^
}
XSETm END
< These 2 methods are the same inside XPTemplate.
*xpt-snippet-repetition*
Repetition is only a special case utilizing expandable, that another
same expandable trigger residing inside the expandable part.
For example the "case"s in "switch". To specify the repetition part,
just wrap the part you want it to repeat with `...^. n is a number and
can be omitted. Take the case from "switch": >
XPT switch
switch (`^) {
`...^ | repetition part
case `^0^ : |
`^ |
break; |
`...^ |
default:
`^
}
<
When you trigger a repetition template it works as below: >
switch () { <------- cursor stays here
`...^
default:
`^
}
< Press <Tab>, the |`...^| is selected. Press <Tab> again to expand the
repetition part. Or press <Cr> |xpt-key-clear| to cancel the
repetition part. These 4 lines are expanded: >
switch () {
case `^ : | expanded
`^ |
break; |
`...^ |
default:
`^
}
< Enter the repetition part. There is another |`...^|, that is the
another repeat trigger.
Press <Tab> 3 times: >
switch () {
case 0 :
break;
case `^ : | selected repetition part
`^ |
break; |
`...^ |
default:
`^
}
<
Using named |`...^| allows you define multiple repetition parts in one
snippet. For example: >
XPT switch
switch (`^) {
`case...^ | repetition part
case `^0^ : |
`^ |
break; |
`case...^ |
default:
`^
}
<
NOTE If you want to use a repetition inside a |xpt-snippet-expandable|
you can't use the normal |`...^| placeholder. Instead use `...{{^ as
in the following example: >
`Maybe...{{^
With repeatable:
`...{{^
- repeat this
`...^
`}}^
`}}^
<
The first `}}^ ends the repetition, the second the expandable.
See |xpt-repetition| for using repetition.
" vim:tw=78:ts=8:sw=8:sts=8:noet:ft=help:norl:

View file

@ -0,0 +1,97 @@
*xpt-snippet-tutorial*
XPTemplate Snippet Tutorial
by drdr.xp
drdr.xp@gmail.com
==============================================================================
|xpt-tutor-define-snippet|
|xpt-tutor-snippet-file|
*xpt-tutor-define-snippet*
This section describes how to define snippet in runtime.
In Vim, call |XPTemplate()| to define a new snippet: >
:call XPTemplate( 'name', 'foo`bar^' )
< And Then in insert-mode, type: >
name<C-\>
< XPT generates: >
foobar
```\_____________ "bar" is selected
< Now you can edit the "bar".
The editable part is called place-holder, see
|xpt-snippet-placeholder|. By default place-holder is quoted with "`"
and "^".
*xpt-tutor-snippet-file*
Snippet defined by |XPTemplate()| can not be stored. To define
snippets which can be loaded every time you edit some kind of file,
you need to create a snippet file.
This first example snippet file is in C language.
1. Create snippet file.
In Linux/Mac: >
vim ~/.vim/ftplugin/c/hello.xpt.vim
< In Windows: >
vim ~/vimfiles/ftplugin/c/hello.xpt.vim
<
2. Define your first snippet.
Type in insert mode: >
skeleton<C-\>
< To create a very simple snippet file skeleton. It may look
like: >
XPTemplate priority=personal+
XPT helloxpt " tips about what this snippet do
Say hello to `xpt^
`xpt^ says hello
<
2.1 Short explanation.
: >
XPTemplate priority=personal+
< These 2 lines declare an XPT snippet file. See
|xpt-snippet-header|.
: >
XPT helloxpt " tips about what this snippet do
< "XPT" is the start symbol of a snippet. See |xpt-snippet|.
"helloxpt" is the trigger key. See |xpt-snippet-name|.
Text after the quote is hint text. See |xpt-snippet-hint|.
: >
Say hello to `xpt^
`xpt^ says hello
< These two lines are snippet body. See |xpt-snippet-body|.
3. Test the first snippet "hello".
Start edit a new file "xpt.c": >
vim xpt.c
< In insert-mode type: >
helloxpt<C-\>
< XPT generates: >
__________| "xpt" is selected
___/
Say hello to xpt
xpt says hello
```\_______________________| the second "xpt" will
| be updated lively
<
4. To create a full featured snippet skeleton, use "xpt" instead of
"skeleton".
5. To learn more about snippet file syntax, read |xpt-snippet-syntax|.
6. Existent snippet files may be good samples, for example
ftplugin/java/java.xpt.vim .
" vim:tw=78:ts=8:sw=8:sts=8:noet:ft=help:norl:

View file

@ -0,0 +1,17 @@
Thanks to:
Agassi
Agassi Yu
chen
Florian Preinstorfer
Gautier DI FOLCO
grassofhust
italiafreeware
kikijump
Kirill Klenov
liu
Lowe Thiderman
twinside
Vincent Berthoux
@bstaint
胡晋

View file

@ -0,0 +1,25 @@
- 4-space indent:
Used in snippet file.
Consistent with different 'tabstop', 'shiftwidth' setting.
- tab indent:
Used internally in XPTemplate.
Produced by converting 4 leading space to one tab.
These two above are VIM setting irrelavent. Snippet file can use either of
them, but 4-space indent is recommended.
- space indent:
Produced by expanding a `tab` char to `&shiftwidth` spaces.
These spaces occupies the same room as actual indent.
This is the second last step before putting text onto screen.
space indent texts are used internally.
Wrapped text is passing through in this style.
- actual indent:
Produced by convert `&tabstop` space to one tab if 'expandtab' not set.
This is the actual indent
The last two are VIM setting relavent.

View file

@ -0,0 +1,354 @@
*xpt-option*
==============================================================================
Table of Content ~
|g:xptemplate_always_show_pum|
|g:xptemplate_brace_complete|
|g:xptemplate_break_undo|
|g:xptemplate_bundle|
|g:xptemplate_close_pum|
|g:xptemplate_cwd_snippet|
|g:xptemplate_debug_log|
|g:xptemplate_highlight|
|g:xptemplate_highlight_nested|
|g:xptemplate_hook_before_cr|
|g:xptemplate_lib_filter|
|g:xptemplate_minimal_prefix|
|g:xptemplate_move_even_with_pum|
|g:xptemplate_ph_pum_accept_empty|
|g:xptemplate_pum_quick_back|
|g:xptemplate_pum_tab_nav|
|g:xptemplate_snippet_folders|
|g:xptemplate_strict|
|g:xptemplate_strip_left|
|g:xptemplate_vars|
*g:xptemplate_always_show_pum*
{default:0}
If set to 1, snippets is not triggered but popup menu shows even when
text user typed before cursor matches a snippet name.
For example, you have three snippets defined of names: "for", "forever"
and "forr". Typing "for<C-\>" results in a popup menu if
|g:xptemplate_always_show_pum| set to 1: >
for
|for |
|forloop |
|forr |
< Otherwise, "for<C-\>" triggers snippet "for".
See also: |g:xptemplate_key_force_pum|.
*g:xptemplate_brace_complete*
{default:1}
If set to 1, bracket characters are automatically expanded to bracket
pairs. For example typing "(" results in: >
( )
\______| cursor stops in mid of pairs of bracket
< "(", "[", "{", "'" and '"' are affected by this setting.
If set to string, only bracket or quote chars included in this setting
will be mapped. For example: >
let g:xptemplate_brace_complete = '([{'
< With this setting, quotes are not mapped.
*g:xptemplate_break_undo*
{default:0}
If set to 1, undo sequence will be broken with |i_CTRL-G_u| before
snippet triggered. This would help on rolling back when mistake was
made.
*g:xptemplate_bundle*
This option specifies what libraries will always be load to its file
type. For example: >
let g:xptemplate_bundle = 'javascript_jquery'
< This tells XPT to load jquery snippet to javascript language.
Or: >
let g:xptemplate_bundle = 'javascript_jquery,c_*'
< It tells XPT to load jquery, and all supplied library snippets for C
language.
Another way to load bundles is |g:XPTaddBundle()|.
*g:xptemplate_close_pum*
{default:0}
If set to 1, when trigger key(|g:xptemplate_key|) is pressed, before
doing anything, popup menu will be closed.
*g:xptemplate_cwd_snippet*
{default:0}
Set this to 1 to enable each vim buffer to automatically load file
".xpt.vim" from current working directory, as snippet file specific to
current directory( or project ).
Current ".xpt.vim" accepts only the most simple form of snippet, the
function call form: >
call XPTemplate( 'foo', '`foo^ says hello' )
<
*g:xptemplate_debug_log*
{default:''}
This option specifies whether and where to store debug log emitted
during xptemplate running. Unless you are a developer of xptempalte,
do not touch it.
Empty string disables any logging.
Non-empty string is interpreted as log file path. "~/" at start will
be replaced with "$HOME/".
Example: >
let g:xptemplate_debug_log = '~/.xpt.log'
<
*g:xptemplate_highlight*
{default:'next'}
Specifies which place holders are high lighted. The value of
|g:xptemplate_highlight| is a comma separated string.
Possible values are: "current", "following" and "next". Example: >
let g:xptemplate_highlight = 'following,next'
<
"current" lets XPTemplate highlight the place holder you are currently
editing. See |XPTcurrentPH|.
For example the first "i" in "for" snippet of C language: >
for ( i = 0; i < len; ++i ) {
\__________________________ highlighted
<
"following" lets XPTemplate highlight slave place holders which are
updated automatically. See |XPTfollowingPH|.
For example the second and third "i" in "for" snippet of C language: >
for ( i = 0; i < len; ++i ) {
\__________\________ highlighted
<
"next" lets XPTemplate highlight the place holders you are going to
edit. See |XPTnextItem|.
For example the "0" and "len" if "for" snippet of C language: >
for ( i = 0; i < len; ++i ) {
\______\\\_____________ highlighted
<
Set |g:xptemplate_highlight| to '' to disable highlight.
*g:xptemplate_highlight_nested*
{default:0}
If set to 1, highlight is also applied to outer snippet, not only the
deepest nested one. For example, If set to 1, the following positions
are highlighted: >
________________________| highlighted
_/ _/ ___/
for ( call( me ) = 0; call < len; call++ ) {
/* cursor */
~~~~~~~~~~~\__________________________| highlighted
}
< The first highlight position is from nested snippet "(". Others are
from outer snippet "for".
*g:xptemplate_hook_before_cr*
{default:''}
Add additional action before default xptemplate action when <CR>
pressed.
By default, xptemplate override key mapping of <CR>(local to
buffer)every time starting to applying a snippet. This might change
user prefered <CR> behavior if user has his own key mapping of <CR>
defined.
This conf let user to fix issues like this.
The following line in .vimrc appends "abc" every time <CR> pressed
during applying snippet: >
let g:xptemplate_hook_before_cr = 'abc'
<
And this appends current time every time <CR> pressed: >
fun! s:OutputDate()
return strftime('%c')
endfunction
inoremap <expr> <Plug>do_my_work <SID>OutputDate()
let g:xptemplate_hook_before_cr = '<Plug>do_my_work'
<
NOTE:
|g:xptemplate_hook_before_cr| does not accept <SID>.
And if you want to use <expr> mapping with
|g:xptemplate_hook_before_cr| , you need a in-the-middle
mapping like it does in the second example.
*g:xptemplate_lib_filter*
{default:.}
Value: unset: do not filter, load any snippet found.
string: regular expression.
list: list of regular expression.
If set, XPT loads only snippets(*.xpt.vim) from 'runtimepath' that
matches it or one of its elements.
NOTE: This option tries to match actual path of a snippet file.
Symbolic link would be resolved.
NOTE: Included snippet like "*/_common/common.xpt.vim" is essential
for other snippet to work thus it won't be affected by this
option.
For example: >
let g:xptemplate_lib_filter = [
\ '/my_snippets\>',
\ '/all_user_snippets/ftplugin/xml/' ]
< The above setting tells XPT to ignore snippet supplied by XPT but to
load only "*/my_snippets/ftplugin/*/*.xpt.vim", and use only "xml"
snippets from "*/all_user_snippets/ftplugin/xml/*.xpt.vim".
It would works the same as with: >
let g:xptemplate_lib_filter = '/my_snippets\>\|/all_user_snippets/ftplugin/xml/'
<
*g:xptemplate_minimal_prefix*
{default:0}
Posssible values: number or "full".
If set it to a number( N ), it means snippet is triggered( or pum
shows ) only when there are at least N |word| letters before cursor.
If set to "full", |g:xptemplate_key| searches for a snippet of name
matching exactly the word before cursor.
For example, you have only one snippet defined with name "xpt". The
following input will trigger "xpt" snippet, if
|g:xptemplate_minimal_prefix| set to 0 ( it also works with value 1 and
2, but not with 3 ): >
xp<C-\>
< "<C-\>" is the default trigger key.
If |g:xptemplate_minimal_prefix| set to "full", the above input can not
trigger "xpt" snippet.
*g:xptemplate_move_even_with_pum*
{default:0}
If set to 1, |g:xptemplate_nav_next| does not care whether pop up menu
shown or not. It will always move cursor to next item.
Otherwise, |g:xptemplate_nav_next| fall back to original mapping. This
could be helpfull for xpt working with supertab together.
*g:xptemplate_ph_pum_accept_empty*
{default:1}
When set to 1 popup menus for place holders accepts an empty input. So
when nothing typed pressing <Tab> closes the popup menu and sends the
cursor to the next place holder.
When not set <Tab> expands the text to the longest match and keeps the
popup menu open.
*g:xptemplate_pum_quick_back*
{default:1}
With popup menu, pressing "<BS>" removes minimal chars to reveil
more options.
If this is set to 0, pressing "<BS>" removes only 1 char.
For example, popup menu created with 3 options: >
"foo", "fooba", "foobar"
<
Typing "fooba" shrinks menu to: >
fooba
foobar
< Now pressing "<BS>" will remove 2 chars: "ba", and leave "foo", the
longest prefix that has 3 options.
Pressing "<BS>" again will remove "foo".
NOTE: Very large list might hang VIM for seconds. In this case set
this to 0 to get better performance.
This feature depends on a prefix dictionary of all of the
options. The prefix dictionary will be created every time
popup menu is called.
*g:xptemplate_pum_tab_nav*
{default:0}
Set to 1 to use <tab>/<S-tab>( shift + tab ) to navigate through pop
up menu. <tab> behaves like <C-n> and <S-tab> behaves like <C-p>. And
<CR> expands snippet.
*g:xptemplate_snippet_folders*
{default:[]}
NOTE: Unless you really want XPTemplate to touch your 'runtimepath',
do NOT use this. This setting changes 'runtimepath' and is
less recommended to use than 'runtimepath'. As you may already
know well about 'runtimepath' and 'ftplugin', it is better for
you to organize snippet files yourself, with 'runtimepath'.
A list to specify which other folders are used as snippet folders.
For example: >
let g:xptemplate_snippet_folders = [
\ $HOME . '/my_snippets',
\ '/all_user_snippets' ]
< Thus the snippet file "$HOME/my_snippets/ftplugin/c/my.c.xpt.vim" can
be loaded to C files.
And "/all_user_snippets/ftplugins/html/all.html.xpt.vim" can be loaded
to HTML files.
*g:xptemplate_strict*
{default:2}
Set to 0 to let XPTemplate do the best maintaining snippet rendering,
even if you have changed text outside of place holders.
Set to 1 to prevent incautious changing text outside place holders.
Otherwise you are free to change text outside of place holders.
Set to 2 to let XPTemplate stop rendering if ANY changes taken to text
outside of place holders.
Example : >
let g:xptemplate_strict = 1
<
*g:xptemplate_strip_left*
{default:1}
When set to 1 wrapper snippets |xpt-wrapper-snippet| remove space
before the first line.
*xpt-personal-var* *g:xptemplate_vars*
g:xptemplate_vars sets personal information variables used in
snippets, like "author" and "email", see |xpt-snippet-variable|.
Variables set with g:xptemplate_vars have the highest priority and
override any other variables set in *.xpt.vim. Syntax: >
let g:xptemplate_vars = 'name=value&name=value...'
< Example: >
let g:xptemplate_vars = '$author=xp\ \&\\\&123&$email=bal@bla'
let g:xptemplate_vars = 'author=xp\ \&\\\&123&email=bal@bla'
< Both the 2 lines above result in: >
'xp\ &\&123' and 'bal@bla'
< Or: >
let g:xptemplate_vars = exists('g:xptemplate_vars') ?
\ g:xptemplate_vars . '&' . '$other=bla'
\ : '$other=bla'
<
Entries are separated with '&'.
You can also set these settings in ftplugin/_common/personal.xpt.vim
in your runtime path using XPTvar |xpt-snippet-variable| (see also
|xpt-customize-variable|).
" vim: tw=78:ts=8:sw=8:sts=8:noet:ft=help:norl:

View file

@ -0,0 +1,107 @@
*xpt-snippet-function*
==============================================================================
Table of Content ~
|Build|
|BuildSnippet|
|Echo|
------------------------------------------------------------------------------
|xpt-snippet-function| can be used in :
|xpt-snippet-instant-value|
|xpt-snippet-preset-value|
|xpt-snippet-default-value|
|xpt-snippet-post-filter|
|xpt-placeholder-ontime-filter|
To define |xpt-snippet-function|, the function container must be
fetched by using |XPTfuncs()|. For example : >
let s:f = XPTfuncs()
fun! s:f.c_printfElts( v )
...
endfunction
< Then function 'c_printfElts' can be used in the snippet : >
XPT printf " printf\(...)
XSET elts=c_printfElts( R( 'pattern' ) )
printf( "`pattern^"`elts^ )
<
NOTE By convention the names of |xpt-snippet-function|s supplied by
XPTemplate start with an upper-case letter. User defined
function names should starts with a lower-case letter.
------------------------------------------------------------------------------
*Build()*
Build({snippet_text})
Build a piece of snippet text to replace the place holder on which
Build() is called.
Argument {snippet_text} is the content of snippet to build.
After calling it, place holder is removed and the first place holder
in this piece of snippet built is selected.
Context: >
XSET ph=Build('`a^ = `0^')
XSET ph|post=Build('`a^ = `0^')
<
See also: |BuildSnippet()|
*BuildSnippet()*
BuildSnippet({snippet})
Build an existent snippet to replace the place holder on which
BuildSnippet() is called.
Argument {snippet} is the name of snippet to build.
After calling it, place holder is removed and the first place holder
in this piece of snippet is selected.
Example snippets: >
XPT parent
XSET x=BuildSnippet( "child" )
-`x^=
XPT child
(`a^, `b^)
<
Type: >
parent<C-\>
< Got: >
-(a, b)=
< {a} and {b} is place holder
Context: >
XSET ph=BuildSnippet('a')
XSET ph|post=BuildSnippet('a')
<
See also: |Build()|
*Echo()*
Echo({string})
Put literal text {string} where it is called.
{string} can be any valid expression.
Place holders in {string} will not be built.
Context it works in: >
`Echo('a')^
XSET ph=Echo('a')
XSET ph|def=Echo('a')
XSET ph|pre=Echo('a')
XSET ph|post=Echo('a')
<
Example: >
XPT now
`Echo( strftime("%c") )^
<
See also: |Build()| |BuildSnippet()|
See also: |xpt-snippet-XSET|
" vim: tw=78:ts=8:sw=8:sts=8:noet:ft=help:norl:

View file

@ -0,0 +1,629 @@
*XPTemplate* For Vim version 7.2. Last change: 2009 Nov 08
*xptemplate*
*xpt*
XP's Snippet Template engine
by drdr.xp
drdr.xp@gmail.com
XPTemplate is a snippet rendering engine.
|xpt-install|
|xpt-usage|
|xpt-personal-var|
|xpt-feature|
|xpt-option|
|xpt-key-bind|
|xpt-tips|
|xpt-with-supertab|
|xpt-customize|
|xpt-write-snippet|
|xpt-snippet-syntax|
|xpt-snippet-tutorial|
|xpt-api|
*xpt-install*
Copy files and directories into one of your 'runtimepath's.
*xpt-usage*
To see what snippets have been defined for the current filetype, press
<C-r><C-r><C-\> in insert mode. See |xpt-key-pum|.
In insert mode type the snippet name and press <C-\> to insert a
snippet. Use <Tab> to navigate through the snippet template.
For example when editing a C file: >
for<C-\>
< generates: >
for ( i = 0; i < len; ++i ) {
/* cursor */
}
< The first "i" being selected is the current item you are editing. "0"
is the next item and you can navigate to it by pressing <Tab>.
To change the snippet trigger (<C-\>) see |xpt-key-trigger|, to change
the navigate key (<Tab>) see |xpt-key-navigate|.
NOTE with some European keyboards <C-\> does NOT work. In this case
you need to specify another key to trigger snippets.
Now type "abc", this results in: >
////````````````````````````| edit area
////
//// ////`````````````````| lively updated
//// //// ////`````'
for ( abc = 0; abc < len; ++abc ) {
/* cursor */
}
< Now press <Tab>, the cursor jumps to "0", the next item: >
//```````````````````````| focus here
for ( abc = 0; abc < len; ++abc ) {
/* cursor */
}
< After pressing <Tab> twice the snippet ends up with cursor staying at
line 2, column 8 (or the value of 'softtabstop'): >
for ( abc = 0; abc < len; ++abc ) {
} \\___________________________| cursor stays here
< The usage is described in more detail below.
For more information regarding the syntax of snippets see
|xpt-snippet-syntax|. To customize settings see |xpt-option|.
*xpt-feature*
Live typing update
Navigate forward and backward |xpt-key-navigate|
Popup hint |xpt-popup|
|xpt-snippet-hint|
Ordered place holders |xpt-snippet-ComeFirst|
Embedded functions and variables |xpt-snippet-function|
Repeatable snippet generation |xpt-repetition|
Nested snippets |xpt-nested|
Wrapper snippets |xpt-wrapper-snippet|
Inclusion on snippet level or file level|xpt-snippet-include|
|xpt-snippet-XPTinclude|
Template priority |xpt-snippet-priority|
Named item or anonymous item |xpt-snippet-item|
Default value |xpt-snippet-default-value|
Preset value |xpt-snippet-preset-value|
Snippet Bundle/Library Support |xpt-bundle|
and more...
*xpt-name-matching*
See |xpt-snippet-name-matching-rule|.
*xpt-popup*
If you type nothing or an incomplete snippet key and press <C-\>, a
popup menu shows up listing all possible snippet keys. For example: >
fo<C-\>
< Shows: >
for
forever
fornn
forr
<
After selecting the item from the popup menu, press <C-\> again to
trigger the snippet.
*xpt-nested*
Templates can be expanded inside another template. There is no
difference between using a nested template or a top-level template.
For example, when you edit a C file type switch<C-\> to generate a
switch block template: >
switch (fn) {
case 0 :
<-------------- cursor stops here after two <Tab>s
break;
...
default:
}
< Now the cursor stops between "case 0 :" and "break;", type: >
if<C-\>
< It becomes: >
switch (fn) { | upper level snippet
case 0 : |
if () { . nested snippet
.
} .
break; | upper level snippet
... |
default: |
|
} |
< Type <Tab>, <Tab>.. to navigate out of the nested snippet: >
switch (fn) {
case 0 :
if () {
}
break;
default:
<--------------cursor stops here
}
< Now cursor stops after "default:" and we get out back to the "switch"
snippet.
==============================================================================
*`...^* *xpt-...* *xpt-repetition*
Some segments can be defined as repeatable, for example the "case"s in
"switch". Specifying the repetition part is easy, just wrap the part
you want it to repeat with `...n^. n is a number and can be omitted if
only one repetition part is used.
Take the case from "switch": >
XPT switch
switch (`^) {
`...^ | repetition part
case `^0^ : |
`^ |
break; |
`...^ |
default:
`^
}
<
When you trigger a repetition template it works as below: >
switch () { <------- cursor stays here
`...^
default:
`^
}
< Press <Tab>, the |`...^| is selected. Press <Tab> again to expand the
repetition part. Or press <Cr> |xpt-key-clear| to cancel the
repetition part. These 4 lines are expanded: >
switch () {
case `^ : | expanded
`^ |
break; |
`...^ |
default:
`^
}
< Enter the repetition part. You may have noticed there is another
|`...^|, that is the another repeat trigger.
Press <Tab> 3 times: >
switch () {
case 0 :
break;
case `^ : | selected repetition part
`^ |
break; |
`...^ |
default:
`^
}
<
See also |xpt-snippet-repetition|.
*xpt-wrapper-snippet*
Wrapper snippets can be triggered in visual mode, place holder marked
as "wrap" is replaced with the text selected in visual mode.
Definition of wrapper snippet has no differences from normal
snippet except it declaring a place holder as wrapping holder. For
example: >
________/---------------------| wrapper declaration
XPT if wrap=job
if (`condition^){
`job^
}
<
For example the following snippet: >
XPT call_ wrap=wrapped
`name^(`wrapped^`, `^)`cursor^
< Use command |V| to select some text and press <C-\>. The selected text
is yanked and popup menu shows.
For example we have one line of text as below: >
a, b
< Select this line with command |V|.
And then press <C-\>, choose "call_" in the popup menu.
And finally it results in : >
name(a, b)
<
NOTE Wrapper snippet declared with "wraponly" can only be triggered
in visual mode, not in insert mode
*xpt-context*
You can define snippets that can only be triggered in certain
circumstances, for example in certain syntax items. Defining context
depended snippets is done by adding another parameter to the
XPTemplate call "{'syn' : 'the context name'}" : >
XPT para syn=comment
@param {`Object^} `name^ `desc^
< Now the snippet "para" can be only triggered in syntax items named
"comment".
==============================================================================
*xpt-key-bind*
Options can be set in |.vimrc| to modify XPTemplate's behaviors.
Key mappings:
|<Plug>XPTrawKey|
|g:xptemplate_key|
|g:xptemplate_key_pum_only|
|g:xptemplate_key_force_pum|
|g:xptemplate_key_visual|
|g:xptemplate_nav_next|
|g:xptemplate_nav_prev|
|g:xptemplate_nav_cancel|
|g:xptemplate_goback|
|g:xptemplate_to_right|
|g:xptemplate_fallback|
See also: |xpt-option|.
*<Plug>XPTrawKey*
Key mapping defined as: >
exe "inoremap <silent> <Plug>XPTrawKey " g:xptemplate_key
<
*i_<C-\>* *v_<C-\>* *xpt-key-trigger* *g:xptemplate_key*
{default:<C-\>}
The key to trigger snippets in insert mode.
Use |g:xptemplate_key| to change this mapping. Example: >
let g:xptemplate_key = '<Tab>'
<
NOTE: You can set this key to <Tab>, as most users do, for
convenience. In this case pressing <Tab> twice results in a normal
<Tab> if there is no snippet key matched.
*i_<C-r><C-r><C-\>* *xpt-key-pum* *g:xptemplate_key_pum_only*
{default:<C-r><C-r>g:xptemplate_key}
Show pop up menu at cursor position. Example: >
let g:xptemplate_key_pum_only = '<S-Tab>'
< By default, this key map is set to '<C-r><C-r>' concatenated with
|g:xptemplate_key| : '<C-r><C-r><C-\>'.
*g:xptemplate_key_force_pum*
{default:<C-r>g:xptemplate_key}
Behave like that with |g:xptemplate_always_show_pum| set.
If more than one snippet starts with( or exactly equals to ) the text
before cursor, pop up menu shows.
This key triggers snippet only when there is only one snippet of name
starts with the text before cursor.
See also: |g:xptemplate_always_show_pum|.
*s_<C-\>* *xpt-key-visual* *g:xptemplate_visual
{default:g:xptemplate_key}
The key to trigger snippets in visual mode.
Use |g:xptemplate_key_visual| to change this mapping. Example: >
let g:xptemplate_key_visual = '<Tab>'
<
*i_<tab>* *s_<tab>* *xpt-key-navigate* *g:xptemplate_nav_next*
{default:<Tab>}
After a snippet was triggered, this key navigates to the next item.
Use |g:xptemplate_nav_next| to change this mapping. Example: >
let g:xptemplate_nav_next = '<C-j>'
<
*i_<S-tab>* *s_<S-tab>* *g:xptemplate_nav_prev*
{default:<S-Tab>}
After a snippet was triggered, press this key to navigate back to the
previous item.
Use |g:xptemplate_nav_prev| to change this mapping. Example: >
let g:xptemplate_nav_prev = '<C-k>'
<
*s_<CR>* *xpt-key-clear* *g:xptemplate_nav_cancel*
{default:<Cr>}
Press to clear current place holder and jump to next.
Use |g:xptemplate_nav_cancel| to change this mapping. Example: >
let g:xptemplate_nav_cancel = '<C-c>'
<
*s_<C-l>* *xpt-key-goto-right* *g:xptemplate_to_right*
{default:<C-l>}
When a place holder is initially selected jump to the end of current
place holder and go into insert mode.
Use |g:xptemplate_to_right| to change this mapping. Example: >
let g:xptemplate_to_right = '<C-;>'
<
*g:xptemplate_fallback*
{default:<Plug>XPTrawKey}
If a try to trigger snippet( by pressing |g:xptemplate_key| ) does not
produce any match( full or partial ), contents of this setting is
output instead.
NOTE: Contents output is similar to user typing. And they CAN be
remapped. This may produce a invoke loop.
The default value of this setting is the literal text of
|g:xptemplate_key|, which is defined by |<Plug>XPTrawKey|.
For example, if you want a completion-popup menu to show when no snippet
matched, you can have this line added into your |.vimrc|: >
let g:xptemplate_fallback = '<C-n>'
<
*n_<C-g>* *i_<C-g>* *xpt-key-goback* *g:xptemplate_goback*
{default:<C-g>}
When you move the cursor outside of place holder you are editing,
pressing this key (in insert mode or normal mode) moves cursor back to
current place holder and selects the place holder text in select mode.
Use |g:xptemplate_goback| to change this mapping. Example: >
let g:xptemplate_goback = '<C-g>'
<
*xpt-customize-highlight*
You can specify which highlight Group to use for each kind of
highlight.
*XPTcurrentPH*
{default:DiffChange}
The highlight group of place holder you are editing. Example: >
highlight link XPTcurrentPH Visual
< This statement tells XPTemplate to use the highlight group "Visual" to
highlight "current" items. See |g:xptemplate_highlight|.
You can also define your highlight group directly. Example: >
highlight XPTcurrentPH gui=none guibg=blue
<
*XPTfollowingPH*
{default:CursorLine}
The highlight group of slave place holders you are editing. Like
|XPTcurrentPH|.
*XPTnextItem*
{default:IncSearch}
The highlight group of item you are going to edit. Like
|XPTcurrentPH|.
*xpt-bundle*
A bundle is a collection of snippets for a certain purpose. For
example a library support bundle like
"ftplugin/javascript/jquery.xpt.vim".
XPTemplate supplies two ways to load bundles: |g:xptemplate_bundle|
and |g:XPTaddBundle()|.
==============================================================================
*xpt-tips*
Want to use XPTemplate with ... together?
|xpt-with-supertab|
*xpt-with-supertab*
If you want to use supertab's <TAB> but you have also set XPT to use
<TAB>.
==============================================================================
*xpt-customize*
Global customization can be done with |xpt-option|.
Two options relate to personal settings:
|g:xptemplate_vars|
This is a easy way to set up your personal information like your name
and email address.
This option actually sets up two variables "$author" and "$email". See
|xpt-snippet-variable|
|g:xptemplate_bundle|
This option sets up which library you want to load.
*xpt-customize-variable*
|xpt-snippet-variable| are used to configure the snippet format.
Customization variables should be defined in a snippet file( like a
file in |xpt-personal-folder|) with "personal" priority, to guarantee
it will not be overrided by other snippet with lower priority. See
|xpt-priority-value|.
To create a snippet file to define your variables, see
|xpt-write-lang-snippet|.
See also: |xpt-customize-variable-format|
|xpt-customize-variable-space|
|xpt-customize-variable-datetime|
*xpt-customize-variable-format*
Each snippet has some variable defined to configure language format.
This is useful when some snippet are shared between languages, like
for loops in C and CPP or to accommodate different user preferences.
Brackets style variables may be defined as below: >
" if () ** {
" else ** {
XPTvar $BRif ' '
" } ** else {
XPTvar $BRel \n
" for () ** {
" while () ** {
" do ** {
XPTvar $BRloop ' '
" struct name ** {
XPTvar $BRstc ' '
" int fun() ** {
" class name ** {
XPTvar $BRfun ' '
< The "**" in comment marks where this variable should be used.
For example following is "for" snippet for both C and CPP: >
XPT for hint=for\ (..;..;++)
for (`i^ = `0^; `i^ < `len^; ++`i^)`$BRloop^{
`cursor^ ******************
}
< In C language "$BRloop" is set to ' '. In CPP "$BRloop" is set to
"\n". You can find them in "ftplugin/c/c.xpt.vim" and
"ftplugin/cpp/cpp.xpt.vim".
In C this snippet results in: >
for ( i = 0; i < 10; ++i ) {
}
< In CPP this snippet results in: >
for ( i = 0; i < 10; ++i )
{
}
<
*xpt-customize-variable-space*
Another set of variables is defined to customize spaces. They are: >
" int fun ** (
" class name ** (
XPTvar $SPfun ''
" int fun( ** arg ** )
" if ( ** condition ** )
" for ( ** statement ** )
" [ ** a, b ** ]
" { ** 'k' : 'v' ** }
XPTvar $SParg ' '
" if ** (
" while ** (
" for ** (
XPTvar $SPcmd ' '
" a = a ** + ** 1
" (a, ** b, ** )
" a ** = ** b
XPTvar $SPop ' '
< For example function snippet defined as below: >
XPT fun
int fun(`$SParg^`args^`$SParg^)
< If "$SParg" is set to ' ', snippet results in: >
int fun( args )
< If "$SParg" is set to '', snippet results in: >
int fun(args)
<
*xpt-customize-variable-datetime*
Variables discussed in this section defines how "date" and "time"
snippet displayed.
"$DATE_FMT" defines "date" snippet format. Default format is: >
XPTvar $DATE_FMT '%Y %b %d'
<
"$TIME_FMT" defines "time snippet format. Default format is: >
XPTvar $TIME_FMT '"%H:%M:%S"'
<
"$DATETIME_FMT" defines "datetime()" function format. Default format is: >
XPTvar $DATETIME_FMT '%c'
<
"datetime()" has no default snippet using it.
*xpt-personal-folder* *xpt-write-snippet*
Snippet file is actually |ftplugin| and with file extension
".xpt.vim", like "c.xpt.vim". So you can manage snippet files just
like the way you manage |ftplugin|.
You have THREE place to put your own snippets:
Path_to_xpt/personal
Recommended. Enough for most users. What you need to do is
putting snippet files into this folder.
Folders in |g:xptemplate_snippet_folders|
Deprecated, use 'runtimepath'.
Other 'runtimepath'
Need to manage 'runtimepath' yourself.
Details are discussed in following section.
*xpt-write-lang-snippet*
You can add snippets of new language, or add snippets to currently
supplied languages, in the same way.
Create a new file in some |ftplugin| directory. For example, if you want
to add some PHP snippet, you can create file: >
path_to_xpt/personal/ftplugin/php/your_snippets.xpt.vim
< Or: >
&runtimepath/ftplugin/php/your_snippets.xpt.vim
< &runtimepath can be ~/.vim in Unix like system, or ~/vimfiles/ folder
in Windows. See 'runtimepath'.
NOTE It is strongly recommended to add your own snippets in
"path_to_xpt/personal".
The file name "your_snippets.xpt.vim" has no limitation except it must
end with ".xpt.vim".
And then write your snippets in that file. Restart Vim to load them.
See |xpt-snippet-syntax| and |xpt-snippet-tutorial|.
*xpt-write-common-snippet*
If you want to add some snippets which don't belong to any language,
or you want to set multiple variables, you can use the "personal
common" snippet file.
1. Rename "personal/ftplugin/_common/personal_example.xpt.vim" to
"personal/ftplugin/_common/personal.xpt.vim". Or create one from
scratch.
2. Add your snippets into the "personal.xpt.vim".
"personal.xpt.vim" is loaded by _common/common.xpt.vim and has the
highest priority. Thus it's always loaded and there are no other
snippets overriding yours.
Example personal/ftplugin/_common/personal.xpt.vim : >
XPTemplate priority=personal
XPTvar $author your_name
XPTvar $email your_email
XPT yoursnippet " tips here
bla bla
< See |xpt-snippet-syntax| and |xpt-snippet-tutorial|.
==============================================================================
" vim:tw=78:ts=8:sw=8:sts=8:noet:ft=help:norl: