*neosnippet.txt* The neo-snippet plugin contains snippet source Version: 4.0 Author: Shougo License: MIT license {{{ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. }}} CONTENTS *neosnippet-contents* 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| FAQ |neosnippet-faq| ============================================================================== INTRODUCTION *neosnippet-introduction* This plugin analyzes snippet files which you can use for completion. It offers functionality similar to snipMate.vim or snippetsEmu.vim. 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. ============================================================================== INSTALL *neosnippet-install* 1: Extract the file and put files in your Vim directory (usually ~/.vim/ or Program Files/Vim/vimfiles on Windows). Note: If you want to complete snippets, you must install neocomplcache (https://github.com/Shougo/neocomplcache.vim) or neocomplete(https://github.com/Shougo/neocomplete.vim). Note: neocomplcache or neocomplete is NOT required! But recommended. Extra snippets files are available in: https://github.com/Shougo/neosnippet-snippets https://github.com/honza/vim-snippets Note: To enable context filetype feature, you must install context_filetype.vim. https://github.com/Shougo/context_filetype.vim ============================================================================== INTERFACE *neosnippet-interface* ------------------------------------------------------------------------------ COMMANDS *neosnippet-commands* *:NeoSnippetMakeCache* :NeoSnippetMakeCache [filetype] Creates a cache for the snippets of the given [filetype]. It automatically chooses the current buffer's file type unless you specify another one by [filetype]. *:NeoSnippetEdit* :NeoSnippetEdit [{options}] [filetype] Opens the snippets for a given [filetype] to edit. It automatically selects the current buffer's filetype unless you specify another one by [filetype]. If the path to [filetype] snippets is a directory, it automatically selects "[filetype].snip" in the [filetype] subdirectory. It edits a snippet file in |g:neosnippet#snippets_directory| with precedence. The snippets are re-cached automatically when you save the file after edit. The following parameters can be used as {options} to modify the behavior of the command. Note: You must escape spaces with a backslash "\". *neosnippet-edit-options-vertical* -vertical Split the window vertically. *neosnippet-edit-options-horizontal* -horizontal Split the window horizontally. Note: The behavior is undefined when both options are set. *neosnippet-edit-options-direction* -direction={direction} Define the split position rule. The default value is "belowleft". *neosnippet-edit-options-split* -split Split the buffer. *neosnippet-edit-options-runtime* -runtime Edit the runtime snippets (built-in defaults) instead of the user snippets defined by 'g:neosnippet#snippets_directory'. *:NeoSnippetSource* :NeoSnippetSource [filename] Load the snippets of a [filetype]. 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. ------------------------------------------------------------------------------ VARIABLES *neosnippet-variables* g:neosnippet#snippets_directory *g:neosnippet#snippets_directory* 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. User defined snippet files are read after the built-in snippet files. If redundant snippets occur they get overwritten and only the last one remains. Note: The neosnippet plug-in loads file type snippets from several files if available. For example if you edit a "Vim" file it loads the snippets from: - "vim.snip*" - "vim_*.snip*" - "vim/**/*.snip" The default value is ''. *g:neosnippet#disable_select_mode_mappings* g:neosnippet#disable_select_mode_mappings This variable disables key-mappings in |Select-mode| where the snippets_complete 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. *g:neosnippet#disable_runtime_snippets* g:neosnippet#disable_runtime_snippets This is a dictionary variable which uses file types as key. If you set the value of a file type entry to 1, this prevents loading all the file type specific built-in snippets. This is very useful to prevent snippet conflicts between self defined snippet files and the built-in snippet files of neosnippet. If you use a "_" as key for an entry this will treat the value of the entry as default value for all file types. Note: This dictionary must be set in your .vimrc. 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 {}. *g:neosnippet#enable_snipmate_compatibility* g:neosnippet#enable_snipmate_compatibility If this variable is not 0, neosnippet will enable the snipMate compatibility feature (For example: Filename() function) and load snipMate snippets automatically from 'runtimepath'. The default value is 0. g:neosnippet#enable_preview *g:neosnippet#enable_preview* If this variable is not 0, neosnippet will enable the preview window feature. The default value is 0. ------------------------------------------------------------------------------ KEY MAPPINGS *neosnippet-key-mappings* *(neosnippet_expand_or_jump)* (neosnippet_expand_or_jump) *s_(neosnippet_expand_or_jump)* s_(neosnippet_expand_or_jump) Expand a snippet in the current cursor position. If there is no snippet available it jumps to the next placeholder of the buffer. *(neosnippet_jump_or_expand)* (neosnippet_jump_or_expand) *s_(neosnippet_jump_or_expand)* s_(neosnippet_jump_or_expand) Jump to the next available placeholder in the buffer. If there is no placeholder it expands a snippet in the current cursor position. *(neosnippet_expand)* (neosnippet_expand) *s_(neosnippet_expand)* s_(neosnippet_expand) Expand a snippet in current cursor position. It only takes effect if there is a snippet text to expand or if you have chosen a snippet from popup menu. *(neosnippet_jump)* (neosnippet_jump) *s_(neosnippet_jump)* s_(neosnippet_jump) Jump to the next placeholder key. It does not expand any snippets. *i_(neosnippet_start_unite_snippet)* i_(neosnippet_start_unite_snippet) 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. *x_(neosnippet_expand_target)* x_(neosnippet_expand_target) Expand the input trigger by a selected target text. *x_(neosnippet_start_unite_snippet_target)* x_(neosnippet_start_unite_snippet_target) Expand the input trigger by a selected target text with the unite interface. Note: The plug-in |unite.vim| is required for that feature. *x_(neosnippet_register_oneshot_snippet)* x_(neosnippet_register_oneshot_snippet) Register oneshot snippet in the current buffer. *neosnippet#expandable()* neosnippet#expandable() You can use this function with imap . It checks if the cursor text is a snippet trigger. This is is useful to save key mappings. *neosnippet#jumpable()* neosnippet#jumpable() You can use this function with imap . It checks if the cursor text is an existing placeholder in current buffer. This is useful to save key mappings. *neosnippet#expandable_or_jumpable()* neosnippet#expandable_or_jumpable() You can use this function with imap . It checks if the cursor text is a snippet trigger or a placeholder. This is is useful to save key mappings. Note: If you don't like to jump to the next placeholder, you must use |neosnippet#expandable()| instead of |neosnippet#expandable_or_jumpable()|. > imap \ neosnippet#expandable_or_jumpable() ? \ "\(neosnippet_expand_or_jump)" : "\" < ------------------------------------------------------------------------------ FUNCTIONS *neosnippet-functions* *neosnippet#get_snippets_directory()* neosnippet#get_snippets_directory() Gets snippet directories. This directories contain runtime snippets directories and |g:neosnippet#snippets_directory| directories. ============================================================================== EXAMPLES *neosnippet-examples* > " Plugin key-mappings. imap (neosnippet_expand_or_jump) smap (neosnippet_expand_or_jump) xmap (neosnippet_expand_target) xmap (neosnippet_start_unite_snippet_target) " SuperTab like snippets behavior. "imap neosnippet#expandable_or_jumpable() ? " \ "\(neosnippet_expand_or_jump)" " \: pumvisible() ? "\" : "\" "smap neosnippet#expandable_or_jumpable() ? " \ "\(neosnippet_expand_or_jump)" " \: "\" " For snippet_complete marker. if has('conceal') set conceallevel=2 concealcursor=i endif " Enable snipMate compatibility feature. " let g:neosnippet#enable_snipmate_compatibility = 1 ============================================================================== SNIPPET SYNTAX *neosnippet-snippet-syntax* It is quite easy to create your own snippets. You can use the example below to get started. Example: > snippet [name] abbr [abbreviation] alias [aliases] regexp [pattern] options [options] if ${1:condition} ${2} endif The snippet syntax is close to the one of |snipMate|. Each snippet starts with some keywords that define the name and modify the expansion and treatment of the snippet. Snippet Keywords: - snippet [name] (Required) 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. - abbr [name] (Optional) You can define an abbreviation for the snippet name. It will be displayed in the drop down selection menu. - alias [aliases] (Optional) Alias names can be use as additional keywords to expand the snippet. You can define multiple aliases using either spaces ' ' or commas ',' as separator. Example > alias hoge hogera hogehoge < - regexp [pattern] (Optional) A pattern can be defined via a regular expression. The snippet expands only when the expression pattern is matched. Example > regexp '^% ' < This snippet works same as "options head". > snippet if regexp '^\s*' if ${1:condition} ${2} endif < - options [options] (Optional) Options influence the snippet behavior. The possible values are: + word This snippet expands by a word boundary. Note: To complete the trigger with snippets_complete, it must be a word character (digits, alphabetical characters or "_"). > snippet date options word `strftime("%d %b %Y")` < + head This snippet expands at the beginning of a line only. Note: This is the same as "prev_word '^'" which is still there for backwards compatibility. > snippet if options head if ${1:condition} ${2} endif < + indent The horizontal position of the snippet will be adjusted to the indent of the line above the snippet after expansion. 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 jump points while expanding the snippet. There are several placeholders available providing different functionality. The structure of a placeholder can be: - ${number:placeholder text} 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. Example > snippet if if ${1:condition} ${2} endif < - ${number:#:placeholder text} 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. Example > snippet if if ${1:#:condition} ${2} endif < - ${number:TARGET} 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. |(neosnippet_expand_target)|. This is very useful if you edit text and decide to put something in an environment or some sort of brackets for folding. Example > snippet if if ${1:#:condition} ${2:TARGET} endif < - ${number} 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. Example > snippet if if ${1:#:condition} ${2:do} endif ${3} < - $number - ${0} 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. Example > snippet namespace namespace ${1:name} { ${0} } // namespace $1 < 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. > snippet code \`${1}\`${2} snippet test ${1:escape \} value} # Substitute "\$0" to "$0" snippet main options head if __FILE__ == \$0 ${1:TARGET} end < A placeholder value can not contain new lines. The snippet below is not valid. > snippet invalid ${1:constructor: (${2:args\}) -> ${3:# do smth}} < 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. > snippet header File: ${1:`expand('%:t')`} ${2:Created at: `strftime("%B %d, %Y")`} < You can also nest placeholders if you escape the special characters. > snippet div
${3}
${4} < In some cases you need to escape the curly brace "}" twice as shown in the example below. > snippet catch options head catch ${1:/${2:pattern: empty, E484, Vim(cmdname):{errmsg\\}\}/} < 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 available for all file types (e.g _.snip). You can include other snippet files from within a snippet file with. > include c.snip < Or if you want to include a whole directory with file type snippets. > include javascript/* < If you include snippet files it can happen that the same snippet name is used multiple times in different snippet files. Neosnippet produces a warning if it detects this. If you want to overwrite a snippet explicitly, please use: > delete snippets_name < 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. Multi snippet feature in snipMate is available. Neosnippet substitutes trigger and descriptions spaces to '_'. > snippet trigger description1 hoge snippet trigger description2 piyo < 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 languages' indent files do not work very well (e.g.: PHP, Python). > snippet if if (${1:/* condition */}) { ${2:// code...} } < Note: "#{string}" is comment string. But it must be in head. > # It is comment string # It is not comment string! < Note: Neosnippet ignores empty or spaces lines in snippet end. If you want to insert empty line in snippet end, you must insert placeholder. > # This is valid. snippet #! abbr #!/usr/bin/env ruby alias shebang options head #!/usr/bin/env ruby ${0} # This is invalid(ignores spaces lines!). snippet #! abbr #!/usr/bin/env ruby alias shebang options head #!/usr/bin/env ruby < ============================================================================== UNITE SOURCES *neosnippet-unite-sources* *neosnippet-unite-source-neosnippet* neosnippet The candidates of the snippet source are neosnippet snippets. and their kind is "snippet". You can use the snippet source with the mapping |(neosnippet_start_unite_snippet)|. 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: > imap (neosnippet_start_unite_snippet) < *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. source actions neosnippet *neosnippet-unite-action-neosnippet* expand Expand snippet (default action) edit Edit snippet preview View snippet definition ============================================================================== FAQ *neosnippet-faq* Q: What if I want to expand a snippet trigger after (, [, " etc...: A: You should use "options word" in the snippet definition. This changes the expansion behavior to a word boundary. > snippet date options word `strftime("%d %b %Y")` < Q: Why does neosnippet not indent the expanded snippet? A: You should use "options indent" in the snippet definition. In default, neosnippet doesn't indent the expanded line. Q: What if Neosnippet conflicts with |LustyJuggler|. 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. > let g:neosnippet#disable_select_mode_mappings = 0 < Q: Error using snipmate-snippets Note: snipmate-snippets is currently vim-snippets. https://github.com/Shougo/neosnippet/issues/86 A: Please try the setting below. It defines the snipMate function. > let g:neosnippet#enable_snipmate_compatibility = 1 < Q: Cannot jump over placeholder https://github.com/Shougo/neosnippet/issues/120 A: You must use smap in .vimrc. > imap neosnippet#expandable_or_jumpable() ? \ "\(neosnippet_expand_or_jump)" : "\" smap neosnippet#expandable_or_jumpable() ? \ "\(neosnippet_expand_or_jump)" : "\" < Because neosnippet uses select-mode to jump over placeholder. Q: I want to disable preview window in neosnippet candidates. A: > set completeopt-=preview < Q: I want to add snippets dynamically. A: You can use |:NeoSnippetSource| for it. Q: I want to delete markers when InsertLeave event. A: You can use |:NeoSnippetClearMarkers| command. > autocmd InsertLeave * NeoSnippetClearMarkers ============================================================================== vim:tw=78:ts=8:ft=help:norl:noet:fen:noet: