97 lines
2.4 KiB
Text
97 lines
2.4 KiB
Text
*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:
|