neosnippet.vim/doc/neosnippet.txt

835 lines
24 KiB
Plaintext
Raw Normal View History

2012-09-27 12:17:07 +00:00
*neosnippet.txt*
2013-06-04 13:39:30 +00:00
The neo-snippet plugin contains snippet source
2012-02-02 04:33:35 +00:00
2015-11-08 23:18:29 +00:00
Version: 5.0
2012-10-16 05:06:45 +00:00
Author: Shougo <Shougo.Matsu@gmail.com>
2017-06-15 00:04:27 +00:00
License: MIT license
2012-02-02 04:33:35 +00:00
2012-09-27 12:17:07 +00:00
CONTENTS *neosnippet-contents*
2012-02-02 04:33:35 +00:00
2012-09-27 12:17:07 +00:00
Introduction |neosnippet-introduction|
Install |neosnippet-install|
Interface |neosnippet-interface|
Commands |neosnippet-commands|
Variables |neosnippet-variables|
Key mappings |neosnippet-key-mappings|
Functions |neosnippet-functions|
Examples |neosnippet-examples|
Snippet syntax |neosnippet-snippet-syntax|
2012-10-30 01:51:33 +00:00
FAQ |neosnippet-faq|
2012-02-02 04:33:35 +00:00
==============================================================================
2012-09-27 12:17:07 +00:00
INTRODUCTION *neosnippet-introduction*
2012-02-02 04:33:35 +00:00
*neosnippet* offers functionality similar to snipMate.vim or snippetsEmu.vim.
2014-02-10 22:04:19 +00:00
This analyzes snippet files which you can use for the completion. Since you
can choose snippets with the neocomplcache/neocomplete interface, you might
have less trouble using them, because you do not have to remember each snippet
name.
2012-02-02 04:33:35 +00:00
==============================================================================
2012-09-27 12:17:07 +00:00
INSTALL *neosnippet-install*
2012-02-02 04:33:35 +00:00
2012-09-30 08:23:02 +00:00
1: Extract the file and put files in your Vim directory
2012-02-02 04:33:35 +00:00
(usually ~/.vim/ or Program Files/Vim/vimfiles on Windows).
2014-01-15 22:43:23 +00:00
Note: If you want to complete snippets, you must install either neocomplcache
(https://github.com/Shougo/neocomplcache.vim) or neocomplete
(https://github.com/Shougo/neocomplete.vim). It's not required, but highly
recommended.
2014-01-15 22:43:23 +00:00
Default snippets files are available in neosnippet-snippets.
https://github.com/Shougo/neosnippet-snippets
Note: Installing the default snippets is optional. If you choose not to install
2014-02-23 23:26:55 +00:00
them, you must set |g:neosnippet#disable_runtime_snippets|. >
let g:neosnippet#disable_runtime_snippets = {
\ '_' : 1,
\ }
2013-02-24 13:23:31 +00:00
2014-01-15 22:43:23 +00:00
Extra snippets files are also available. e.g.:
2013-04-05 00:32:56 +00:00
https://github.com/honza/vim-snippets
2013-03-24 08:22:20 +00:00
2014-01-15 22:43:23 +00:00
Note: To enable context-filetype feature, you must install
context_filetype.vim. This allows you to use snippets not only depend on the
current 'filetype' of the file, but also depends on the cursor location, such
as javascript inside html, or lua inside Vim scripts.
2013-05-28 10:22:54 +00:00
https://github.com/Shougo/context_filetype.vim
2012-02-02 04:33:35 +00:00
==============================================================================
2012-09-27 12:17:07 +00:00
INTERFACE *neosnippet-interface*
2012-02-02 04:33:35 +00:00
------------------------------------------------------------------------------
2012-09-27 12:17:07 +00:00
COMMANDS *neosnippet-commands*
2012-02-02 04:33:35 +00:00
2012-09-30 10:10:25 +00:00
*:NeoSnippetMakeCache*
2013-11-12 08:13:52 +00:00
:NeoSnippetMakeCache [filetype]
2013-04-11 20:02:59 +00:00
Creates a cache for the snippets of the given [filetype]. It
2012-12-08 13:57:59 +00:00
automatically chooses the current buffer's file type unless you
2013-04-11 20:02:59 +00:00
specify another one by [filetype].
2012-02-02 04:33:35 +00:00
*:NeoSnippetEdit*
2013-11-12 08:13:52 +00:00
:NeoSnippetEdit [{options}] [filetype]
2015-11-07 04:15:47 +00:00
Opens the snippets for a given [filetype] to edit. It
automatically selects the current buffer's filetype unless you
specify another one by [filetype].
2012-11-03 03:33:18 +00:00
If the path to [filetype] snippets is a directory, it
2013-04-11 20:02:59 +00:00
automatically selects "[filetype].snip" in the [filetype]
2012-11-03 03:33:18 +00:00
subdirectory.
It edits a snippet file in |g:neosnippet#snippets_directory|
2012-11-03 03:33:18 +00:00
with precedence. The snippets are re-cached automatically
2012-10-30 08:25:43 +00:00
when you save the file after edit.
2012-11-03 03:33:18 +00:00
The following parameters can be used as {options} to modify
the behavior of the command. Note: You must escape spaces with
a backslash "\".
2012-05-05 15:19:01 +00:00
2015-11-07 03:59:40 +00:00
Note: You must set |g:neosnippet#snippets_directory| before
using it.
2012-09-30 10:10:25 +00:00
*neosnippet-edit-options-vertical*
-vertical
2012-10-30 08:25:43 +00:00
Split the window vertically.
2012-05-05 15:19:01 +00:00
2012-09-30 10:10:25 +00:00
*neosnippet-edit-options-horizontal*
-horizontal
2012-10-30 08:25:43 +00:00
Split the window horizontally.
Note: The behavior is undefined when both options are set.
2012-02-02 04:33:35 +00:00
2012-09-30 10:10:25 +00:00
*neosnippet-edit-options-direction*
-direction={direction}
2012-11-03 03:33:18 +00:00
Define the split position rule. The default value is
"belowleft".
2012-09-30 10:10:25 +00:00
*neosnippet-edit-options-split*
-split
2012-10-30 08:25:43 +00:00
Split the buffer.
2012-09-30 10:10:25 +00:00
*neosnippet-edit-options-runtime*
-runtime
2013-04-11 20:02:59 +00:00
Edit the runtime snippets (built-in defaults) instead of the
2012-11-03 03:33:18 +00:00
user snippets defined by 'g:neosnippet#snippets_directory'.
2012-09-30 10:10:25 +00:00
2012-11-03 03:40:08 +00:00
*:NeoSnippetSource*
2013-11-12 08:13:52 +00:00
:NeoSnippetSource [filename]
2013-04-11 20:02:59 +00:00
Load the snippets of a [filetype].
2012-11-03 03:40:08 +00:00
Note: The loaded snippets are enabled in current buffer only.
*:NeoSnippetClearMarkers*
:NeoSnippetClearMarkers
Clear current markers.
Note: If you delete markers, you cannot jump to next
placeholder.
2012-02-02 04:33:35 +00:00
------------------------------------------------------------------------------
2012-09-27 12:17:07 +00:00
VARIABLES *neosnippet-variables*
2012-02-02 04:33:35 +00:00
2012-09-30 09:04:48 +00:00
g:neosnippet#snippets_directory *g:neosnippet#snippets_directory*
2012-05-05 15:19:01 +00:00
This variable appoints a path to user-defined snippet files.
You can set multiple values in comma-separated string or list.
Non existing directories are ignored.
2012-05-05 15:19:01 +00:00
2012-11-03 03:33:18 +00:00
User defined snippet files are read after the built-in snippet
2012-12-08 13:57:59 +00:00
files. If redundant snippets occur they get overwritten and
2012-11-03 03:33:18 +00:00
only the last one remains.
2012-11-03 03:33:18 +00:00
Note: The neosnippet plug-in loads file type snippets from
several files if available. For example if you edit a "Vim"
2013-04-11 20:02:59 +00:00
file it loads the snippets from:
2012-10-30 16:47:01 +00:00
2015-12-23 11:27:57 +00:00
- "vim.snip"
- "vim.snippets"
- "vim_*.snip"
- "vim_*.snippets"
2014-01-15 22:43:23 +00:00
- "vim/**/*.snip"
2015-12-23 11:27:57 +00:00
- "vim/**/*.snippets"
2012-05-05 09:08:56 +00:00
The default value is ''.
2012-02-02 04:33:35 +00:00
2012-09-30 09:04:48 +00:00
*g:neosnippet#disable_select_mode_mappings*
2013-11-12 08:13:52 +00:00
g:neosnippet#disable_select_mode_mappings
2012-11-03 03:33:18 +00:00
This variable disables key-mappings in |Select-mode| where the
2014-01-10 20:46:47 +00:00
neosnippet performs the snippet completion. Usually it is
better to leave it as it is. But if you have troubles with the
buffer switcher LustyJuggler you can switch them off.
The default value is 1.
2012-02-02 04:33:35 +00:00
2012-09-30 09:04:48 +00:00
*g:neosnippet#disable_runtime_snippets*
2013-11-12 08:13:52 +00:00
g:neosnippet#disable_runtime_snippets
2012-10-30 16:47:01 +00:00
This is a dictionary variable which uses file types as key.
2012-11-03 03:33:18 +00:00
If you set the value of a file type entry to 1, this prevents
2014-01-10 20:53:23 +00:00
loading "neosnippets" directories from 'runtimepath'. This is
very useful to prevent snippet conflicts between self defined
snippet files and the built-in snippet files of neosnippet. If
you use an "_" as key for an entry this will treat the value of
2014-01-10 20:53:23 +00:00
the entry as default value for all file types.
Note: This dictionary must be set in your .vimrc.
2012-02-02 04:33:35 +00:00
For example:
>
let g:neosnippet#disable_runtime_snippets = {
\ 'c' : 1, 'cpp' : 1,
\ }
" which disables all runtime snippets
let g:neosnippet#disable_runtime_snippets = {
\ '_' : 1,
\ }
<
The default value is {}.
2012-02-02 04:33:35 +00:00
*g:neosnippet#enable_snipmate_compatibility*
2013-11-12 08:13:52 +00:00
g:neosnippet#enable_snipmate_compatibility
If this variable is not 0, neosnippet will enable the snipMate
compatibility features:
1. Define Filename() function.
2. Load |g:snippets_dir| and snipMate snippets files from
2014-01-10 20:53:23 +00:00
'runtimepath'.
3. Enable file snippets feature in snipMate.
The default value is 0.
*g:neosnippet#expand_word_boundary*
g:neosnippet#expand_word_boundary
If it is not 0, neosnippet will expand snippets by a word
boundary.
2014-03-11 17:57:48 +00:00
Note: It must be initialized before snippet loading.
The default value is 0.
*g:neosnippet#enable_conceal_markers*
g:neosnippet#enable_conceal_markers
If this variable is not 0, neosnippet will use the |conceal|
markers.
The default value is 1.
*g:neosnippet#enable_completed_snippet*
g:neosnippet#enable_completed_snippet
If this variable is not 0, neosnippet can expand the function
prototype.
2015-12-11 18:07:13 +00:00
The default value is 0.
*g:neosnippet#enable_auto_clear_markers*
g:neosnippet#enable_auto_clear_markers
If this variable is not 0, neosnippet will clear the markers
in the buffer when |BufWritePost|, |CursorMoved| and
|CursorMovedI| autocmd.
2016-09-10 22:04:43 +00:00
Note: The feature does not work for multi lines snippets.
If you want to clear them, you should use
|:NeoSnippetClearMarkers| instead.
The default value is 1.
*g:neosnippet#scope_aliases*
g:neosnippet#scope_aliases
It is a dictionary that associating certain filetypes with
other snippet files.
The key is filetype, and the value is comma separated snippet
filenames excluded extensions.
It works like |g:snipMate.scope_aliases|.
The default value is {}. >
let g:neosnippet#scope_aliases = {}
let g:neosnippet#scope_aliases['ruby'] = 'ruby,ruby-rails'
2014-05-21 14:06:27 +00:00
g:neosnippet#data_directory *g:neosnippet#data_directory*
2014-05-11 08:56:27 +00:00
Specifies directory for neosnippet cache. If the directory
doesn't exist the directory will be automatically generated.
Default value is "$XDG_CACHE_HOME/neosnippet" or
2014-06-27 13:06:42 +00:00
expand("~/.cache/neosnippet"); the absolute path of it.
2014-05-11 08:56:27 +00:00
*b:neosnippet_disable_snippet_triggers*
b:neosnippet_disable_snippet_triggers
Specifies the triggers which disables in the buffer.
It is useful to disable some snippet triggers.
2012-02-02 04:33:35 +00:00
------------------------------------------------------------------------------
2012-09-27 12:17:07 +00:00
KEY MAPPINGS *neosnippet-key-mappings*
2012-02-02 04:33:35 +00:00
2017-01-01 09:55:44 +00:00
*i_<Plug>(neosnippet_expand_or_jump)*
i_<Plug>(neosnippet_expand_or_jump)
2012-10-29 22:45:46 +00:00
*s_<Plug>(neosnippet_expand_or_jump)*
2013-11-12 08:13:52 +00:00
s_<Plug>(neosnippet_expand_or_jump)
2012-11-03 03:33:18 +00:00
Expand a snippet in the current cursor position. If there is
no snippet available it jumps to the next placeholder of the
buffer.
2012-05-05 09:08:56 +00:00
2017-01-01 09:55:44 +00:00
*i_<Plug>(neosnippet_jump_or_expand)*
i_<Plug>(neosnippet_jump_or_expand)
2012-10-29 22:45:46 +00:00
*s_<Plug>(neosnippet_jump_or_expand)*
2013-11-12 08:13:52 +00:00
s_<Plug>(neosnippet_jump_or_expand)
2012-11-03 03:33:18 +00:00
Jump to the next available placeholder in the buffer. If there
is no placeholder it expands a snippet in the current cursor
position.
2012-02-02 04:33:35 +00:00
2017-01-01 09:55:44 +00:00
*i_<Plug>(neosnippet_expand)*
i_<Plug>(neosnippet_expand)
2012-10-29 22:45:46 +00:00
*s_<Plug>(neosnippet_expand)*
2013-11-12 08:13:52 +00:00
s_<Plug>(neosnippet_expand)
2012-11-03 03:33:18 +00:00
Expand a snippet in current cursor position. It only takes
effect if there is a snippet text to expand or if you have
2013-06-04 13:39:30 +00:00
chosen a snippet from popup menu.
2012-09-30 09:04:48 +00:00
2017-01-01 09:55:44 +00:00
*i_<Plug>(neosnippet_jump)*
i_<Plug>(neosnippet_jump)
2012-10-29 22:45:46 +00:00
*s_<Plug>(neosnippet_jump)*
2013-11-12 08:13:52 +00:00
s_<Plug>(neosnippet_jump)
2012-11-03 03:33:18 +00:00
Jump to the next placeholder key. It does not expand any
snippets.
2012-02-02 04:33:35 +00:00
2012-10-04 05:21:05 +00:00
*i_<Plug>(neosnippet_start_unite_snippet)*
2013-11-12 08:13:52 +00:00
i_<Plug>(neosnippet_start_unite_snippet)
2012-11-03 03:33:18 +00:00
Starts the unite snippet source. You can expand a snippet by
the unite interface.
Note: The plug-in |unite.vim| is required for that feature.
2012-09-30 09:04:48 +00:00
2012-10-29 22:45:46 +00:00
*x_<Plug>(neosnippet_expand_target)*
2013-11-12 08:13:52 +00:00
x_<Plug>(neosnippet_expand_target)
Expand the input trigger by a selected target text.
2012-10-29 22:45:46 +00:00
2012-11-03 03:33:18 +00:00
*x_<Plug>(neosnippet_register_oneshot_snippet)*
2013-11-12 08:13:52 +00:00
x_<Plug>(neosnippet_register_oneshot_snippet)
Register oneshot snippet in the current buffer.
2012-09-30 09:13:49 +00:00
*neosnippet#expandable()*
2013-11-12 08:13:52 +00:00
neosnippet#expandable()
2013-04-11 20:02:59 +00:00
You can use this function with imap <expr>. It checks if
the cursor text is a snippet trigger. This is useful to save
key mappings.
2012-09-30 09:13:49 +00:00
*neosnippet#jumpable()*
2013-11-12 08:13:52 +00:00
neosnippet#jumpable()
You can use this function with imap <expr>. It checks if the
cursor text is an existing placeholder in current buffer. This
is useful to save key mappings.
*neosnippet#expandable_or_jumpable()*
2013-11-12 08:13:52 +00:00
neosnippet#expandable_or_jumpable()
2013-04-11 20:02:59 +00:00
You can use this function with imap <expr>. It checks if
the cursor text is a snippet trigger or a placeholder. This is
useful to save key mappings.
2013-04-11 20:02:59 +00:00
Note: If you don't like to jump to the next placeholder, you must use
2013-01-26 21:56:06 +00:00
|neosnippet#expandable()| instead of
|neosnippet#expandable_or_jumpable()|.
>
imap <expr><C-l>
\ neosnippet#expandable_or_jumpable() ?
\ "\<Plug>(neosnippet_expand_or_jump)" : "\<C-n>"
<
2015-11-03 06:06:23 +00:00
*neosnippet#anonymous()*
neosnippet#anonymous({snippet})
2015-10-21 12:13:14 +00:00
It defines anonymous snippet.
{snippet} is snippet definition.
{options} is snippet option.
You can expand snippet definition without defining snippet
2015-10-21 22:26:08 +00:00
trigger.
Note: You can use this function with |map-<expr>|.
2015-10-21 22:26:08 +00:00
>
2015-10-21 12:13:14 +00:00
inoremap <silent> ((
2015-12-19 03:17:31 +00:00
\ <C-r>=neosnippet#anonymous('\left(${1}\right)${0}')<CR>
" OR
inoremap <expr><silent> ((
2015-12-19 03:17:31 +00:00
\ neosnippet#anonymous('\left(${1}\right)${0}')
2015-10-21 22:26:08 +00:00
<
2015-11-03 06:06:23 +00:00
*neosnippet#expand()*
neosnippet#expand({trigger})
It expands the snippet trigger.
2015-11-03 08:45:03 +00:00
{trigger} is snippet trigger.
Note: You can use this function with |map-<expr>|.
>
inoremap <silent> test
2015-11-03 06:06:23 +00:00
\ i<C-r>=neosnippet#expand('date_english')<CR>
2015-11-03 08:45:03 +00:00
nnoremap <silent><expr> test
\ neosnippet#expand('date_english')
2015-11-03 06:06:23 +00:00
2012-06-06 01:05:36 +00:00
------------------------------------------------------------------------------
2012-09-27 12:17:07 +00:00
FUNCTIONS *neosnippet-functions*
2012-06-06 01:05:36 +00:00
2012-09-30 09:13:49 +00:00
*neosnippet#get_snippets_directory()*
2013-11-12 08:13:52 +00:00
neosnippet#get_snippets_directory()
Gets snippet directories. These directories contain runtime
2012-09-30 09:13:49 +00:00
snippets directories and |g:neosnippet#snippets_directory|
2012-06-06 01:05:36 +00:00
directories.
2012-09-30 09:13:49 +00:00
2012-02-02 04:33:35 +00:00
==============================================================================
2012-09-27 12:17:07 +00:00
EXAMPLES *neosnippet-examples*
2012-02-02 04:33:35 +00:00
>
" Plugin key-mappings.
2017-01-08 12:34:29 +00:00
" Note: It must be "imap" and "smap". It uses <Plug> mappings.
2012-09-30 09:13:49 +00:00
imap <C-k> <Plug>(neosnippet_expand_or_jump)
smap <C-k> <Plug>(neosnippet_expand_or_jump)
2012-10-29 22:45:46 +00:00
xmap <C-k> <Plug>(neosnippet_expand_target)
2012-05-05 09:08:56 +00:00
" SuperTab like snippets' behavior.
2017-01-08 12:34:29 +00:00
" Note: It must be "imap" and "smap". It uses <Plug> mappings.
2015-08-31 20:03:27 +00:00
"imap <expr><TAB>
" \ pumvisible() ? "\<C-n>" :
" \ neosnippet#expandable_or_jumpable() ?
2015-09-25 23:21:11 +00:00
" \ "\<Plug>(neosnippet_expand_or_jump)" : "\<TAB>"
"smap <expr><TAB> neosnippet#expandable_or_jumpable() ?
2015-08-31 20:03:27 +00:00
" \ "\<Plug>(neosnippet_expand_or_jump)" : "\<TAB>"
2012-05-05 09:08:56 +00:00
2015-06-23 12:51:53 +00:00
" For conceal markers.
2012-02-02 04:33:35 +00:00
if has('conceal')
2015-01-28 12:51:56 +00:00
set conceallevel=2 concealcursor=niv
2012-02-02 04:33:35 +00:00
endif
" Enable snipMate compatibility feature.
" let g:neosnippet#enable_snipmate_compatibility = 1
2012-02-02 04:33:35 +00:00
==============================================================================
2012-09-27 12:17:07 +00:00
SNIPPET SYNTAX *neosnippet-snippet-syntax*
2012-02-02 04:33:35 +00:00
2013-04-10 21:11:16 +00:00
It is quite easy to create your own snippets. You can use the example below to
2013-04-23 13:19:53 +00:00
get started.
2012-02-02 04:33:35 +00:00
2015-12-23 11:27:57 +00:00
Note: The snippets file extension must be ".snip" or ".snippets".
2012-02-02 04:33:35 +00:00
Example:
2012-10-30 20:45:29 +00:00
2012-02-02 04:33:35 +00:00
>
2012-11-03 03:33:18 +00:00
snippet [name]
abbr [abbreviation]
alias [aliases]
2012-12-08 13:57:59 +00:00
regexp [pattern]
2012-11-03 03:33:18 +00:00
options [options]
if ${1:condition}
${2}
endif
The snippet syntax is close to the one of |snipMate|. Each snippet starts with
2013-04-23 13:19:53 +00:00
some keywords that define the name and modify the expansion and treatment of
the snippet.
2012-10-21 08:51:07 +00:00
2012-10-30 20:45:29 +00:00
Snippet Keywords:
2012-11-05 07:41:01 +00:00
- snippet [name] (Required)
2012-10-30 20:45:29 +00:00
2013-04-23 13:19:53 +00:00
Each snippet starts with the keyword "snippet". This keyword is
directly followed by the snippet name. The snippet name is used to
expand the snippet.
2012-10-30 20:45:29 +00:00
2012-11-05 07:41:01 +00:00
- abbr [name] (Optional)
2012-10-30 16:47:01 +00:00
2013-04-23 13:19:53 +00:00
You can define an abbreviation for the snippet name. It will be
2013-06-04 13:39:30 +00:00
displayed in the drop down selection menu.
2012-10-30 20:45:29 +00:00
2012-11-05 07:41:01 +00:00
- alias [aliases] (Optional)
2012-10-30 20:45:29 +00:00
2013-04-23 13:19:53 +00:00
Alias names can be use as additional keywords to expand the snippet.
You can define multiple aliases using either spaces ' ' or commas ','
as separator.
2012-10-30 20:45:29 +00:00
Example
2012-10-30 16:47:01 +00:00
2012-02-02 04:33:35 +00:00
>
alias hoge hogera hogehoge
2012-02-02 04:33:35 +00:00
<
2012-05-05 15:19:01 +00:00
2012-11-05 07:41:01 +00:00
- regexp [pattern] (Optional)
2012-11-03 06:35:27 +00:00
2013-04-23 13:19:53 +00:00
A pattern can be defined via a regular expression. The snippet expands
only when the expression pattern is matched.
2012-11-03 06:35:27 +00:00
Example
2012-11-03 06:35:27 +00:00
>
regexp '^% '
2012-11-03 06:35:27 +00:00
<
2013-06-28 06:37:51 +00:00
This snippet works same as "options head".
>
snippet if
2013-06-29 15:20:44 +00:00
regexp '^\s*'
2013-06-28 06:37:51 +00:00
if ${1:condition}
${2}
endif
<
2012-11-05 07:41:01 +00:00
- options [options] (Optional)
2012-10-30 20:45:29 +00:00
Options influence the snippet behavior. The possible values are:
2012-10-31 07:35:20 +00:00
2013-04-23 13:19:53 +00:00
+ word This snippet expands by a word boundary.
2014-01-10 20:46:47 +00:00
Note: To complete the trigger with neosnippet, it must be a
word character (digits, alphabetical characters or "_").
2012-10-31 07:35:20 +00:00
>
2013-06-28 06:37:51 +00:00
snippet date
options word
`strftime("%d %b %Y")`
2012-10-31 07:35:20 +00:00
<
+ head This snippet expands at the beginning of a line only.
2012-11-03 03:33:18 +00:00
Note: This is the same as "prev_word '^'" which is still
2012-10-31 07:35:20 +00:00
there for backwards compatibility.
>
2013-06-28 06:37:51 +00:00
snippet if
options head
if ${1:condition}
${2}
endif
2012-10-31 07:35:20 +00:00
<
2013-04-23 13:19:53 +00:00
+ indent The horizontal position of the snippet will be adjusted
2013-04-10 13:17:05 +00:00
to the indent of the line above the snippet after expansion.
2012-10-31 07:35:20 +00:00
The snippet itself starts below the part that contains the options, snippet
aliases and keywords, described above. It contains the snippet which gets
expanded which can contain several placeholders. The placeholders are used as
2013-04-23 13:19:53 +00:00
jump points while expanding the snippet. There are several placeholders
available providing different functionality.
2012-10-30 20:45:29 +00:00
The structure of a placeholder can be:
- ${number:default placeholder text}
2012-11-03 03:33:18 +00:00
2013-04-23 13:19:53 +00:00
The placeholder starts with a dollar sign "$". The number of a
placeholder and the placeholder text are separated by a colon ":".
They are surrounded by a pair of curly braces "{}". The placeholder
text is displayed after the snippet expansion and will be replaced by
your text. If you jump over the snippet and do not insert any text in
that placeholder position the text remains there. This can be used as
a default value for a certain position.
2012-02-02 04:33:35 +00:00
Example
2012-10-30 16:47:01 +00:00
2012-02-02 04:33:35 +00:00
>
2012-11-03 03:33:18 +00:00
snippet if
if ${1:condition}
${2}
endif
2012-02-02 04:33:35 +00:00
<
2012-10-30 16:47:01 +00:00
- ${number:#:optional placeholder text}
2012-10-30 20:45:29 +00:00
2013-04-23 13:19:53 +00:00
In this kind of placeholder the number is followed by the hash
character "#". If you jump over this placeholder and do not insert
any text, the placeholder text will be removed.
2012-10-30 20:45:29 +00:00
Example
2012-10-30 16:47:01 +00:00
2012-10-17 08:43:23 +00:00
>
2012-11-03 03:33:18 +00:00
snippet if
if ${1:#:condition}
${2}
endif
2012-10-30 20:45:29 +00:00
<
- ${number:TARGET}
2013-04-23 13:19:53 +00:00
This is the target placeholder which is replaced by text from a visual
selection.
Note: You need to make a visual selection and expand your
snippet with the key mapping below for this to work.
2012-10-30 20:45:29 +00:00
|<Plug>(neosnippet_expand_target)|.
2012-10-30 20:45:29 +00:00
This is very useful if you edit text and decide to put something in an
environment or some sort of brackets for folding.
2012-10-30 20:45:29 +00:00
Example
2012-10-30 20:45:29 +00:00
>
2012-11-03 03:33:18 +00:00
snippet if
if ${1:#:condition}
${2:TARGET}
endif
2012-10-30 20:45:29 +00:00
<
- ${number}
2013-04-23 13:19:53 +00:00
This is a placeholder which you can use as a simple jump position.
This can be useful if you edit a placeholder inside of some sort of
brackets or environment and want to go on behind it after that.
2012-10-30 20:45:29 +00:00
Example
2012-10-30 20:45:29 +00:00
>
2012-11-03 03:33:18 +00:00
snippet if
if ${1:#:condition}
${2:do}
endif
2012-11-03 03:33:18 +00:00
${3}
2012-10-17 08:43:23 +00:00
<
2012-10-30 20:45:29 +00:00
- $number
2013-04-23 13:19:53 +00:00
- ${0}
2012-10-30 20:45:29 +00:00
2013-04-23 13:19:53 +00:00
This is a synchronized placeholder. Sometimes it is required to repeat
a value in several positions inside a snippet. If you set the number
of this placeholder to the same number as one of the other
placeholders in the snippet, it will repeat its content. $1 is
synchronized to ${1} and so on. ${0} will be the final jump
placeholder.
2012-10-30 20:45:29 +00:00
Example
2012-10-30 16:47:01 +00:00
2012-02-02 04:33:35 +00:00
>
snippet namespace
namespace ${1:name} {
2013-06-28 06:37:51 +00:00
${0}
} // namespace $1
2012-02-02 04:33:35 +00:00
<
2012-10-30 16:47:01 +00:00
2013-04-23 13:19:53 +00:00
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.
2012-10-30 16:47:01 +00:00
2012-10-19 09:38:52 +00:00
>
2012-11-03 03:33:18 +00:00
snippet code
\`${1}\`${2}
2012-10-30 20:45:29 +00:00
2012-11-03 03:33:18 +00:00
snippet test
${1:escape \} value}
# Substitute "\$0" to "$0"
snippet main
options head
if __FILE__ == \$0
${1:TARGET}
end
2012-10-19 09:38:52 +00:00
<
2012-10-30 16:47:01 +00:00
2013-04-23 13:19:53 +00:00
A placeholder value can not contain new lines. The snippet below is
not valid.
2012-02-02 04:33:35 +00:00
>
2012-11-03 03:33:18 +00:00
snippet invalid
${1:constructor: (${2:args\}) ->
${3:# do smth}}
2012-02-02 04:33:35 +00:00
<
2012-05-05 15:19:01 +00:00
2012-10-30 20:45:29 +00:00
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. Here the "%:t"
gets expanded to the name of the current active file and the current time gets
inserted by expanding the output of the strftime command.
2012-10-30 20:45:29 +00:00
2012-02-02 04:33:35 +00:00
>
2012-11-03 03:33:18 +00:00
snippet header
File: ${1:`expand('%:t')`}
${2:Created at: `strftime("%B %d, %Y")`}
2012-02-02 04:33:35 +00:00
<
2012-10-30 20:45:29 +00:00
You can also nest placeholders if you escape the special characters.
2012-10-30 20:45:29 +00:00
2012-10-29 20:09:50 +00:00
>
2012-11-03 03:33:18 +00:00
snippet div
<div ${1:id="${2:someid\}"}>${3}</div>${4}
2012-10-29 20:09:50 +00:00
<
2012-10-30 20:45:29 +00:00
2013-04-23 13:19:53 +00:00
In some cases you need to escape the curly brace "}" twice as shown in the
example below.
2012-10-30 20:45:29 +00:00
2012-10-29 22:45:46 +00:00
>
2012-11-03 03:33:18 +00:00
snippet catch
options head
catch ${1:/${2:pattern: empty, E484, Vim(cmdname):{errmsg\\}\}/}
2012-10-29 22:45:46 +00:00
<
2012-10-30 20:45:29 +00:00
This is because ${1:} substitutes the pattern to "/${2:pattern: empty, E484,
Vim(cmdname):{errmsg\}}" and ${2:} substitutes the pattern to "pattern: empty,
E484, Vim(cmdname):{errmsg}"
If you create a snippet file and prepend the filename with a "_" neosnippet
treats the snippets inside the file as global. This means that they will be
2012-11-03 03:33:18 +00:00
available for all file types (e.g _.snip). You can include other snippet files
from within a snippet file with.
2012-10-30 20:45:29 +00:00
2012-10-19 02:02:08 +00:00
>
2012-10-30 20:45:29 +00:00
include c.snip
2012-10-19 02:02:08 +00:00
<
2012-02-02 04:33:35 +00:00
Or if you want to include a whole directory with file type snippets.
2012-10-20 03:55:19 +00:00
2012-02-02 04:33:35 +00:00
>
2012-10-30 20:45:29 +00:00
include javascript/*
2012-02-02 04:33:35 +00:00
<
2012-10-30 20:45:29 +00:00
If you include snippet files it can happen that the same snippet name is used
2014-05-11 08:46:20 +00:00
multiple times in snippet files. Neosnippet produces a warning if it detects
this. If you want to overwrite a snippet explicitly, please use:
2012-10-30 20:45:29 +00:00
2012-02-02 04:33:35 +00:00
>
2012-10-30 20:45:29 +00:00
delete snippets_name
2012-02-02 04:33:35 +00:00
<
2012-10-30 20:45:29 +00:00
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.
2013-04-23 13:19:53 +00:00
Multi snippet feature in snipMate is available. Neosnippet substitutes trigger
and descriptions spaces to '_'.
2012-02-02 04:33:35 +00:00
>
snippet trigger description1
2012-10-19 02:02:08 +00:00
hoge
2012-02-02 04:33:35 +00:00
snippet trigger description2
2012-10-19 02:02:08 +00:00
piyo
2012-02-02 04:33:35 +00:00
<
2012-10-19 02:02:08 +00:00
If you use hard-tab for indentation inside a snippet file, neosnippet will use
2012-07-02 02:37:14 +00:00
'shiftwidth' instead of Vim indent plugin. This feature is useful while some
languages' indent files do not work very well (e.g.: PHP, Python).
2012-02-02 04:33:35 +00:00
>
snippet if
2012-11-03 03:33:18 +00:00
if (${1:/* condition */}) {
${2:// code...}
}
2012-02-02 04:33:35 +00:00
<
2012-10-21 09:03:10 +00:00
2012-11-05 03:01:14 +00:00
Note: "#{string}" is comment string. But it must be in head.
>
# It is comment string
# It is not comment string!
<
2012-11-05 07:41:01 +00:00
2013-04-23 13:19:53 +00:00
Note: Neosnippet ignores empty or spaces lines in snippet end. If you want to
insert empty line in snippet end, you must insert placeholder.
2012-11-05 07:41:01 +00:00
>
# This is valid.
snippet #!
abbr #!/usr/bin/env ruby
alias shebang
options head
#!/usr/bin/env ruby
2012-11-05 07:41:01 +00:00
${0}
2012-11-05 07:59:39 +00:00
# This is invalid(ignores spaces lines!).
2012-11-05 07:41:01 +00:00
snippet #!
abbr #!/usr/bin/env ruby
alias shebang
options head
#!/usr/bin/env ruby
2015-12-23 12:05:12 +00:00
You can load a Vim script file for snippets.
>
source go.vim
2012-11-05 07:41:01 +00:00
<
2015-12-23 12:05:12 +00:00
2012-02-02 04:33:35 +00:00
==============================================================================
2012-09-27 12:17:07 +00:00
UNITE SOURCES *neosnippet-unite-sources*
2012-02-02 04:33:35 +00:00
2013-12-30 22:50:41 +00:00
*neosnippet-unite-source-neosnippet*
neosnippet
2012-11-03 03:33:18 +00:00
The candidates of the snippet source are neosnippet snippets.
and their kind is "snippet". You can use the snippet source
with the mapping |<Plug>(neosnippet_start_unite_snippet)|.
2013-12-30 22:50:41 +00:00
But you can also execute it by ":Unite neosnippet". The
snippet source offers an edit action you can use to edit the
snippet files.
Example:
2012-02-02 04:33:35 +00:00
>
2012-09-30 09:13:49 +00:00
imap <C-s> <Plug>(neosnippet_start_unite_snippet)
2012-02-02 04:33:35 +00:00
<
2013-02-17 05:58:57 +00:00
*neosnippet-unite-source-neosnippet/user*
neosnippet/user
The candidates of the user snippet files.
*neosnippet-unite-source-neosnippet/runtime*
neosnippet/runtime
The candidates of the runtime snippet files.
2012-02-02 04:33:35 +00:00
source actions
2013-12-30 22:50:41 +00:00
neosnippet *neosnippet-unite-action-neosnippet*
2012-05-05 15:19:01 +00:00
expand Expand snippet (default action)
2012-02-02 04:33:35 +00:00
edit Edit snippet
preview View snippet definition
2012-10-30 01:51:33 +00:00
==============================================================================
FAQ *neosnippet-faq*
2012-11-15 23:05:14 +00:00
Q: What if I want to expand a snippet trigger after (, [, " etc...:
2012-10-30 01:51:33 +00:00
2012-11-03 03:33:18 +00:00
A: You should use "options word" in the snippet definition. This changes the
expansion behavior to a word boundary or set
2015-12-29 12:27:13 +00:00
|g:neosnippet#expand_word_boundary|.
2012-10-30 01:51:33 +00:00
>
snippet date
options word
`strftime("%d %b %Y")`
<
2012-11-03 03:33:18 +00:00
Q: Why does neosnippet not indent the expanded snippet?
2012-10-30 01:58:26 +00:00
A: You should use "options indent" in the snippet definition. In default,
neosnippet doesn't indent the expanded line.
2012-10-30 01:58:26 +00:00
Q: What if Neosnippet conflicts with |LustyJuggler|.
2012-10-30 02:45:29 +00:00
http://www.vim.org/scripts/script.php?script_id=2050
A: Please try below settings:
Note: But you must unmap the mappings in select mode manually.
2012-10-30 02:45:29 +00:00
>
let g:neosnippet#disable_select_mode_mappings = 0
<
Q: Error using snipmate-snippets
2013-04-05 00:32:56 +00:00
Note: snipmate-snippets is currently vim-snippets.
https://github.com/Shougo/neosnippet/issues/86
2013-04-11 20:02:59 +00:00
A: Please try the setting below. It defines the snipMate function.
>
2013-04-23 14:28:11 +00:00
let g:neosnippet#enable_snipmate_compatibility = 1
<
2013-02-24 13:30:59 +00:00
Q: Cannot jump over placeholder
https://github.com/Shougo/neosnippet/issues/120
A: You must use smap in .vimrc.
>
imap <expr><TAB> neosnippet#expandable_or_jumpable() ?
\ "\<Plug>(neosnippet_expand_or_jump)" : "\<TAB>"
smap <expr><TAB> neosnippet#expandable_or_jumpable() ?
\ "\<Plug>(neosnippet_expand_or_jump)" : "\<TAB>"
<
Because neosnippet uses select-mode to jump over placeholder.
2013-03-23 01:42:24 +00:00
Q: I want to disable preview window in neosnippet candidates.
2013-03-16 03:42:20 +00:00
A:
>
set completeopt-=preview
<
2013-04-18 07:24:57 +00:00
Q: I want to add snippets dynamically.
A: You can use |:NeoSnippetSource| for it.
2013-12-25 13:04:02 +00:00
Q: I want to delete markers when InsertLeave event.
2013-12-25 13:04:02 +00:00
A: You can use |:NeoSnippetClearMarkers| command. >
autocmd InsertLeave * NeoSnippetClearMarkers
2014-01-15 22:43:23 +00:00
Q: Why did you separate default snippets from neosnippet core?
2014-01-15 22:43:23 +00:00
A: Because users should choose default snippet collection.
neosnippet has many forks, but almost all forked users change default snippet
files.
https://github.com/Shougo/neosnippet.vim/network
If splitted default snippets, users can fork and change it easily.
2015-08-23 05:54:52 +00:00
Q: I want to complete function arguments using neosnippet like clang_complete.
A: Yes, you can. You can just complete the candidate from completion window
and expand the candidate as trigger.
Note: It works in "func(arg1, arg2, ...)" prototypes only.
Note: It is experiental feature.
Note: |v:completed_item| feature is needed.
2012-02-02 04:33:35 +00:00
==============================================================================
2013-01-11 14:59:59 +00:00
vim:tw=78:ts=8:ft=help:norl:noet:fen:noet: