VimPlugin: ultisnips

From wikinotes

Ultisnipps allows you to configure templates to insert into your code.
It also provides interactive fields, allowing you to satisfy all requirements of a snippet.
You may also extract/insert info automatically, like the current date.

NOTE:

Once you have finished completing a snippet, you can not re-edit it.


WARNING:

Issues with ultisnips and vim with both python 2/3.
Moving to VimPlugin: vim-snipmate

Documentation

official docs https://github.com/SirVer/ultisnips/blob/master/doc/UltiSnips.txt
github https://github.com/SirVer/ultisnips
snippet examples https://github.com/honza/vim-snippets/tree/master/snippets

Locations

&runtimepath/UltiSnips/&ft/*.snippets' (~/.vim/UltiSnips) snippets location (plugins can add snippets)
~/.vim/bundle/ultisnips/autoload/UltiSnips.vim available snippet functions

Example

See More: https://github.com/honza/vim-snippets/tree/master/snippets

# ~/.vim/UltiSnips/python.snippets

snippet <completion_word>
	========================
	file: $1
	date: $2
	desc: ${3:default description here}
	========================
	$0
endsnippet

Explanation

snippet <completion_word>
	## defines the start of a new snippet, and determines the 
	## word to be completed.

$1
	## Each $<num> variable indicates a unique field.
	## That field can be used as a variable, which is automatically
	## reused wherever else it is reused.


$0
	## Where the cursor should be placed after completing the snippet


${3:default description here}
	## Set default values for a snippet field

endsnippet
	## ends the snippet clause (this appears to be optional).

Usage

:call UltiSnips#ExpandSnippetOrJump()     "expand a snippet (if on space immediately following the completion word)

:call UltiSnips#JumpForwards()            "technically the command used to skip forwards. must be bound to key.
:call UltiSnips#JumpBackwards()           "technically the command used to skip backwards. must be bound to key.
:call UltiSnips#ListSnippets()            "list of all snippet files

" if FZF.vim is installed
:Snippets                                 " search snippets

Syntax

snippet-file naming

Snippets are activated based on vim's current filetype. Any snippet on the snippets path is valid if it's filepath matches any of the following:

*/$ft.snippets
*/$ft_*.snippets
$ft/*.snippets

embedding code

shell

You can run shell code within snippets by enclosing it in backticks `.

snippet header
	date: ${1:`date +%d.%m.%y`}
endsnippet

vimscript

viml code is executed by being enclosed in backticks with a prefix of !v.

snippet header
	date: ${1: `!v strftime("%b %d, %Y")`}
endsnippet

python

python code is executed by being enclosed in backticks with a prefix of !p.

snippet header
	date: ${1: `!p import datetime.datetime;datetime.now().strftime('%b %d, %Y')`}
endsnippet

Python snippets (in addition to viml, of course) can access certain information from vim. The following variables are the defaults:

   fn      - The current filename
   path    - The complete path to the current file
   t       - The values of the placeholders, t[1] is the text of ${1}, etc.
   snip    - UltiSnips.TextObjects.SnippetUtil object instance. Has methods
             that simplify indentation handling.
context - Result of context condition. See |UltiSnips-context-snippets|.

Read more about it here: https://github.com/SirVer/ultisnips/blob/master/doc/UltiSnips.txt under 4.4.3 Python.