" This file contains some simple functions that attempt to emulate some of the " behaviour of 'Snippets' from the OS X editor TextMate, in particular the " variable bouncing and replacement behaviour. " " This is the first release and so is a bit rough around the edges. " " USAGE: " " 'source' the file and define your 'snippets' using the Iabbr command. " The syntax of the command is the same as for 'iabbr'. " Variables are tagged with @'s. " " Example: " " Iabbr forin for @element@ in @collection@@element@.@@end " " The above will expand to the following (indenting may differ): " " for @element@ in @collection@ " @element@.@@ " end " " The cursor will be placed after the first @ in insert mode. " Pressing will 'tab' to the next place marker (@collection@) in " insert mode. Adding text between the @@s and then hitting will " remove the @s and replace all markers with a similar identifier. " " Eg: " With the cursor at the pipe, hitting will replace: " for @MyVariableName|element@ in @collection@ " @element@.@@ " end " " with (the pipe shows the cursor placement): " " for MyVariableName in @|collection@ " MyVariableName.@@ " end " " Enjoy. " " Future Features: " " Commands in tags. The first named tag should be able to define a default " value. Further tags with the same name should be allowed to have a command " instead of a default tag which would then be executed with 'execute'. The " idea is to allow for TextMate style functionality e.g. getter/setter snippets " for Obj-C. Added in 0.3 " " Known Bugs: " " If the abbreviation starts with a tag and is inserted at the start of the line " then the cursor will not be placed in the correct tag. " " FIXED Empty tag replacement. Changing an empty tag will change all remaining " empty tags " " FIXED Short variable names. Having a single character in the tags will mess up " the insert point. " " FIXED Autoindentation breaks and too much whitespace can be swallowed. " Caused by using 'i' instead of 'a' in the redefined command. if exists('loaded_snippet') || &cp finish endif let g:snip_mod_tab = 1 let loaded_snippet=1 " {{{ Set up variables if !exists("g:snip_start_tag") let g:snip_start_tag = "<" endif if !exists("g:snip_end_tag") let g:snip_end_tag = ">" endif if !exists("g:snip_elem_delim") let g:snip_elem_delim = ":" endif let s:just_expanded = 0 let g:snip_disable_tab = 0 " }}} " {{{ Map Jumper to the default key if not set already if ( !hasmapto( 'Jumper', 'i' ) ) if g:snip_mod_tab == 1 imap Jumper else imap Jumper endif endif imap