Some improvements in the helpfile chapter about the snippet syntax.

This commit is contained in:
cpfaff 2013-04-09 22:57:13 +02:00
parent 8126b9c3f5
commit 304131521d

View File

@ -394,80 +394,85 @@ Snippet Keywords:
- snippet [name] (Required) - snippet [name] (Required)
Each snippet starts with the keyword "snippet". This keyword is directly Each snippet starts with the keyword "snippet". This keyword is directly
followed by the snippet name. The snippet name is used for the expansion of followed by the snippet name. The snippet name is used for the expansion of
the snippet. the snippet.
- abbr [name] (Optional) - abbr [name] (Optional)
Here you can define an abbreviation of the snippet which will be used in You can define an abbreviation for the snippet. It will be displayed in
the drop down menu of neocomplcache. the drop down selection menu of neocomplcache.
- alias [aliases] (Optional) - alias [aliases] (Optional)
If you specify an alias it will be also used to expand a snippet. You can Alias names can be use as additional keywords to expand a snippet. You can
define multiple aliases either using the separators ' ' or ','. define multiple aliases using either spaces ' ' or commas ',' as separator.
Example Example
> >
alias hoge hogera hogehoge alias hoge hogera hogehoge
< <
- regexp [pattern] (Optional) - regexp [pattern] (Optional)
This snippet expands when it matched by the regexp pattern only. A pattern can be defined via a regular expression. The snippet expands only
when the expression pattern is matched.
Example Example
> >
regexp '^% ' regexp '^% '
< <
- options [options] (Optional) - options [options] (Optional)
Options influence the snippet behavior. The possible options are: Options influence the snippet behavior. The possible values are:
+ word This snippet expands by a word boundary. Note: To complete + word This snippet expands by a word boundary. Note: To complete
the trigger in snippets_complete, it must be word(digits or the trigger in snippets_complete, it must be a word character
alphabet characters or "_") characters. (digits, an alphabetical characters or "_").
> >
snippet date snippet date
options word options word
`strftime("%d %b %Y")` `strftime("%d %b %Y")`
< <
+ head This snippet expands on the beginning of a line only. + head This snippet expands on the beginning of a line only.
Note: This is the same as "prev_word '^'" which is still Note: This is the same as "prev_word '^'" which is still
there for backwards compatibility. there for backwards compatibility.
> >
snippet if snippet if
options head options head
if ${1:condition} if ${1:condition}
${2} ${2}
endif endif
< <
+ indent Neosnippet indents the snippet after expansion to the same + indentation The horizontal position of the snippet will be adjusted
to the indent the snippet after expansion to the same
column as the line above. column as the line above.
Below the keywords starts the snippet which gets expanded. After the snippet The snippet itself starts below the part that contains the options, snippet
expansion you can jump to the placeholders and replace them with desired text. aliases and kekywords, described above. It contains the snippet which gets
expanded and can contain several place holders. The placeholders are used as
jump points inside the snippet. There are several placeholder available and they
provide diffrent functionality.
The structure of a placeholder can be: The structure of a placeholder can be:
- ${number:placeholder text} - ${number:placeholder text}
Here the number of the placeholder and the placeholder text that are The number of a placeholder and the placeholder text are separated
separated by a ":" are embraced by a pair of "{}". The text is displayed by a ":". They are embraced by a pair of curly braces "{}". The
after the snippet expansion and gets replaced by your text. If you jump placeholder text is displayed after the snippet expansion and will be
over the snippet and do not insert any text in that position the replaced by your text. If you jump over the snippet and do not insert
placeholder text remains there. This can be used as a standard value for a any text in that position the placeholder text remains there. This can
certain position. be used as a default value for a certain position.
Example Example
> >
snippet if snippet if
@ -478,11 +483,11 @@ The structure of a placeholder can be:
- ${number:#:placeholder text} - ${number:#:placeholder text}
Here the number is followed by the "#" character. If you jump over this In this type of placeholder the number is followed by the "#" character.
placeholder and do not insert any text, the placeholder text will be If you jump over this placeholder and do not insert any text, the placeholder
removed. text will be removed.
Example Example
> >
snippet if snippet if
@ -493,17 +498,16 @@ The structure of a placeholder can be:
- ${number:TARGET} - ${number:TARGET}
This is the target placeholder which will be replaced by the text which is This is the target placeholder which is replaced by text from a visual
selected before snippet expansion. selection. Note: You need to expand your snippet with the key mapping below
Note: You need to expand you snippet with the key mapping below for this to for this to work.
work.
|<Plug>(neosnippet_expand_target)|. |<Plug>(neosnippet_expand_target)|.
This is very useful if you edit text and decide to put something in an This is very useful if you edit text and decide to put something in an
environment or some sort of brackets. environment or some sort of brackets for folding.
Example Example
> >
snippet if snippet if
@ -514,40 +518,40 @@ The structure of a placeholder can be:
- ${number} - ${number}
This is a placeholder which you can use as a simple jump position. This This is a placeholder which you can use as a simple jump position. This can be
can be useful if you edit a placeholder inside of some sort of brackets or useful if you edit a placeholder inside of some sort of brackets or environment
environment and after that want to go on behind that. and after that want to go on behind that.
Example Example
> >
snippet if snippet if
if ${1:#:condition} if ${1:#:condition}
${2:do} ${2:do}
endif endif
${3} ${3}
< <
- $number - $number
This is a synchronized placeholder. Sometimes it is required to repeat a This is a synchronized placeholder. Sometimes it is required to repeat a value
value in several places inside a snippet. If you set the number of this in several places inside a snippet. If you set the number of this placeholder
placeholder to the same number as one of the other placeholders in the to the same number as one of the other placeholders in the snippet, it will
snippet it will repeat its content. $1 is synchronized to ${1} and so on. repeat its content. $1 is synchronized to ${1} and so on. $0 will be the final
$0 will be the final jump placeholder. jump placeholder.
Example Example
> >
snippet namespace snippet namespace
namespace ${1:name} { namespace ${1:name} {
${0} ${0}
} // namespace $1 } // namespace $1
< <
Note: If you like to include characters in snippets that already have a Note: If you like to include characters in snippets that already have a
special meaning to neosnippet you need to escape them with a backslash. special meaning to neosnippet you need to escape them with a backslash.
> >
snippet code snippet code
@ -560,11 +564,11 @@ special meaning to neosnippet you need to escape them with a backslash.
snippet main snippet main
options head options head
if __FILE__ == \$0 if __FILE__ == \$0
${1:TARGET} ${1:TARGET}
end end
< <
A placeholder value can not contain new lines. The snippet below isn't valid. A placeholder value can not contain new lines. The snippet below isn't valid.
> >
snippet invalid snippet invalid
@ -574,8 +578,8 @@ A placeholder value can not contain new lines. The snippet below isn't valid.
Vim has a built-in expression evaluation. You can also use this feature inside Vim has a built-in expression evaluation. You can also use this feature inside
of snippets if you use back ticks like in the example below where "%:t" gets of snippets if you use back ticks like in the example below where "%:t" gets
expanded to name of the current active file when the snippet gets expanded and expanded to the name of the current active file and the current time gets
the current time gets inserted by the expansion of the strftime command. inserted by the expansion of the strftime command.
> >
snippet header snippet header
@ -628,8 +632,9 @@ detects this. If you want to overwrite a snippet explicitly, please use:
After that you can redefine the snippet. But this does not work if you include After that you can redefine the snippet. But this does not work if you include
external snippet files. There will be no warning when snippets get overwritten. external snippet files. There will be no warning when snippets get overwritten.
Multi snippet feature in snipMate is available. Multi snippet feature in snipMate is available. Neosnippet substitutes trigger
Neosnippet substitutes trigger and descriptions spaces to '_'. and descriptions spaces to '_'.
> >
snippet trigger description1 snippet trigger description1
hoge hoge
@ -637,9 +642,9 @@ Neosnippet substitutes trigger and descriptions spaces to '_'.
piyo piyo
< <
If you use hard-tab for indentation in snippet file, neosnippet will use If you use hard-tab for indentation inside a snippet file, neosnippet will use
'shiftwidth' instead of Vim indent plugin. This feature is useful while some 'shiftwidth' instead of Vim indent plugin. This feature is useful while some
languages' indent files can not work very well (e.g.: PHP, Python). languages' indent files do not work very well (e.g.: PHP, Python).
> >
snippet if snippet if
if (${1:/* condition */}) { if (${1:/* condition */}) {