1
0
Fork 0
mirror of synced 2024-11-22 16:55:34 -05:00

Updated plugins

This commit is contained in:
amix 2013-08-03 14:50:12 +02:00
parent a448b32309
commit 351979d3e0
20 changed files with 603 additions and 670 deletions

View file

@ -259,6 +259,10 @@ fu! s:match_window_opts()
\ s:mw =~ 'min:[^,]\+' ? str2nr(matchstr(s:mw, 'min:\zs\d\+')) : 1 \ s:mw =~ 'min:[^,]\+' ? str2nr(matchstr(s:mw, 'min:\zs\d\+')) : 1
let [s:mw_max, s:mw_min] = [max([s:mw_max, 1]), max([s:mw_min, 1])] let [s:mw_max, s:mw_min] = [max([s:mw_max, 1]), max([s:mw_min, 1])]
let s:mw_min = min([s:mw_min, s:mw_max]) let s:mw_min = min([s:mw_min, s:mw_max])
let s:mw_res =
\ s:mw =~ 'results:[^,]\+' ? str2nr(matchstr(s:mw, 'results:\zs\d\+'))
\ : min([s:mw_max, &lines])
let s:mw_res = max([s:mw_res, 1])
endf endf
"}}}1 "}}}1
" * Open & Close {{{1 " * Open & Close {{{1
@ -576,7 +580,7 @@ fu! s:Update(str)
let s:martcs = &scs && str =~ '\u' ? '\C' : '' let s:martcs = &scs && str =~ '\u' ? '\C' : ''
let pat = s:matcher == {} ? s:SplitPattern(str) : str let pat = s:matcher == {} ? s:SplitPattern(str) : str
let lines = s:nolim == 1 && empty(str) ? copy(g:ctrlp_lines) let lines = s:nolim == 1 && empty(str) ? copy(g:ctrlp_lines)
\ : s:MatchedItems(g:ctrlp_lines, pat, s:winmaxh) \ : s:MatchedItems(g:ctrlp_lines, pat, s:mw_res)
cal s:Render(lines, pat) cal s:Render(lines, pat)
endf endf
@ -1605,8 +1609,7 @@ endf
fu! ctrlp#syntax() fu! ctrlp#syntax()
if ctrlp#nosy() | retu | en if ctrlp#nosy() | retu | en
for [ke, va] in items(s:hlgrps) | cal ctrlp#hicheck('CtrlP'.ke, va) | endfo for [ke, va] in items(s:hlgrps) | cal ctrlp#hicheck('CtrlP'.ke, va) | endfo
if !hlexists('CtrlPLinePre') if synIDattr(synIDtrans(hlID('Normal')), 'bg') !~ '^-1$\|^$'
\ && synIDattr(synIDtrans(hlID('Normal')), 'bg') !~ '^-1$\|^$'
sil! exe 'hi CtrlPLinePre '.( has("gui_running") ? 'gui' : 'cterm' ).'fg=bg' sil! exe 'hi CtrlPLinePre '.( has("gui_running") ? 'gui' : 'cterm' ).'fg=bg'
en en
sy match CtrlPNoEntries '^ == NO ENTRIES ==$' sy match CtrlPNoEntries '^ == NO ENTRIES ==$'

View file

@ -112,12 +112,12 @@ fu! ctrlp#bookmarkdir#accept(mode, str)
en en
endf endf
fu! ctrlp#bookmarkdir#add(dir) fu! ctrlp#bookmarkdir#add(dir, ...)
let str = 'Directory to bookmark: ' let str = 'Directory to bookmark: '
let cwd = a:dir != '' ? a:dir : s:getinput(str, getcwd(), 'dir') let cwd = a:dir != '' ? a:dir : s:getinput(str, getcwd(), 'dir')
if cwd == '' | retu | en if cwd == '' | retu | en
let cwd = fnamemodify(cwd, ':p') let cwd = fnamemodify(cwd, ':p')
let name = s:getinput('Bookmark as: ', cwd) let name = a:0 && a:1 != '' ? a:1 : s:getinput('Bookmark as: ', cwd)
if name == '' | retu | en if name == '' | retu | en
let name = tr(name, ' ', ' ') let name = tr(name, ' ', ' ')
cal s:savebookmark(name, cwd) cal s:savebookmark(name, cwd)

View file

@ -62,6 +62,7 @@ let s:types = {
\ 'lisp' : '%slisp%slisp%sf', \ 'lisp' : '%slisp%slisp%sf',
\ 'lua' : '%slua%slua%sf', \ 'lua' : '%slua%slua%sf',
\ 'make' : '%smake%smake%sm', \ 'make' : '%smake%smake%sm',
\ 'ocaml' : '%socaml%socaml%scmMvtfCre',
\ 'pascal' : '%spascal%spascal%sfp', \ 'pascal' : '%spascal%spascal%sfp',
\ 'perl' : '%sperl%sperl%sclps', \ 'perl' : '%sperl%sperl%sclps',
\ 'php' : '%sphp%sphp%scdvf', \ 'php' : '%sphp%sphp%scdvf',

View file

@ -22,32 +22,36 @@ cal add(g:ctrlp_ext_vars, {
let s:id = g:ctrlp_builtins + len(g:ctrlp_ext_vars) let s:id = g:ctrlp_builtins + len(g:ctrlp_ext_vars)
" Utilities {{{1 " Utilities {{{1
fu! s:findcount(str) fu! s:findcount(str)
let [tg, fname] = split(a:str, '\t\+\ze[^\t]\+$') let [tg, ofname] = split(a:str, '\t\+\ze[^\t]\+$')
let tgs = taglist('^'.tg.'$') let tgs = taglist('^'.tg.'$')
if len(tgs) < 2 if len(tgs) < 2
retu [1, 1] retu [0, 0, 0, 0]
en en
let bname = fnamemodify(bufname('%'), ':p') let bname = fnamemodify(bufname('%'), ':p')
let fname = expand(fnamemodify(simplify(fname), ':s?^[.\/]\+??:p:.'), 1) let fname = expand(fnamemodify(simplify(ofname), ':s?^[.\/]\+??:p:.'), 1)
let [fnd, ct, pos, idx] = [0, 0, 0, 0] let [fnd, cnt, pos, ctgs, otgs] = [0, 0, 0, [], []]
wh idx < len(tgs) for tgi in tgs
if bname == fnamemodify(tgs[idx]["filename"], ':p') let lst = bname == fnamemodify(tgi["filename"], ':p') ? 'ctgs' : 'otgs'
cal insert(tgs, remove(tgs, idx)) cal call('add', [{lst}, tgi])
brea endfo
en let ntgs = ctgs + otgs
let idx += 1 for tgi in ntgs
endw let cnt += 1
for each in tgs let fulname = fnamemodify(tgi["filename"], ':p')
let ct += 1
let fulname = fnamemodify(each["filename"], ':p')
if stridx(fulname, fname) >= 0 if stridx(fulname, fname) >= 0
\ && strlen(fname) + stridx(fulname, fname) == strlen(fulname) \ && strlen(fname) + stridx(fulname, fname) == strlen(fulname)
let fnd += 1 let fnd += 1
let pos = ct let pos = cnt
en en
if fnd > 1 | brea | en
endfo endfo
retu [fnd, pos] let cnt = 0
for tgi in ntgs
let cnt += 1
if tgi["filename"] == ofname
let [fnd, pos] = [0, cnt]
en
endfo
retu [1, fnd, pos, len(ctgs)]
endf endf
fu! s:filter(tags) fu! s:filter(tags)
@ -89,27 +93,33 @@ endf
fu! ctrlp#tag#accept(mode, str) fu! ctrlp#tag#accept(mode, str)
cal ctrlp#exit() cal ctrlp#exit()
let str = matchstr(a:str, '^[^\t]\+\t\+[^\t]\+\ze\t') let str = matchstr(a:str, '^[^\t]\+\t\+[^\t]\+\ze\t')
let [tg, fnd] = [split(str, '^[^\t]\+\zs\t')[0], s:findcount(str)] let [tg, fdcnt] = [split(str, '^[^\t]\+\zs\t')[0], s:findcount(str)]
let cmds = { let cmds = {
\ 't': ['tab sp', 'tab stj'], \ 't': ['tab sp', 'tab stj'],
\ 'h': ['sp', 'stj'], \ 'h': ['sp', 'stj'],
\ 'v': ['vs', 'vert stj'], \ 'v': ['vs', 'vert stj'],
\ 'e': ['', 'tj'], \ 'e': ['', 'tj'],
\ } \ }
let cmd = fnd[0] == 1 ? cmds[a:mode][0] : cmds[a:mode][1] let utg = fdcnt[3] < 2 && fdcnt[0] == 1 && fdcnt[1] == 1
let cmd = !fdcnt[0] || utg ? cmds[a:mode][0] : cmds[a:mode][1]
let cmd = a:mode == 'e' && ctrlp#modfilecond(!&aw) let cmd = a:mode == 'e' && ctrlp#modfilecond(!&aw)
\ ? ( cmd == 'tj' ? 'stj' : 'sp' ) : cmd \ ? ( cmd == 'tj' ? 'stj' : 'sp' ) : cmd
let cmd = a:mode == 't' ? ctrlp#tabcount().cmd : cmd let cmd = a:mode == 't' ? ctrlp#tabcount().cmd : cmd
if fnd[0] == 1 if !fdcnt[0] || utg
if cmd != '' if cmd != ''
exe cmd exe cmd
en en
let save_cst = &cst let save_cst = &cst
set cst& set cst&
cal feedkeys(":".fnd[1]."ta ".tg."\r", 'nt') cal feedkeys(":".( utg ? fdcnt[2] : "" )."ta ".tg."\r", 'nt')
let &cst = save_cst let &cst = save_cst
el el
cal feedkeys(":".cmd." ".tg."\r", 'nt') let ext = ""
if fdcnt[1] < 2 && fdcnt[2]
let [sav_more, &more] = [&more, 0]
let ext = fdcnt[2]."\r".":let &more = ".sav_more."\r"
en
cal feedkeys(":".cmd." ".tg."\r".ext, 'nt')
en en
cal ctrlp#setlcdir() cal ctrlp#setlcdir()
endf endf

View file

@ -123,7 +123,7 @@ heights of the match window: >
let g:ctrlp_match_window = '' let g:ctrlp_match_window = ''
< <
Example: > Example: >
let g:ctrlp_match_window = 'bottom,order:btt,min:1,max:10' let g:ctrlp_match_window = 'bottom,order:btt,min:1,max:10,results:10'
< <
The position: (default: bottom) The position: (default: bottom)
top - show the match window at the top of the screen. top - show the match window at the top of the screen.
@ -137,6 +137,9 @@ The minimum and maximum heights:
min:{n} - show minimum {n} lines (default: 1). min:{n} - show minimum {n} lines (default: 1).
max:{n} - show maximum {n} lines (default: 10). max:{n} - show maximum {n} lines (default: 10).
The maximum number of results:
results:{n} - list maximum {n} results (default: sync with max height).
Note: When a setting isn't set, its default value will be used. Note: When a setting isn't set, its default value will be used.
*'g:ctrlp_switch_buffer'* *'g:ctrlp_switch_buffer'*
@ -1285,6 +1288,8 @@ Special thanks:~
* Christopher Fredén <github.com/icetan> * Christopher Fredén <github.com/icetan>
* Zahary Karadjov <github.com/zah> * Zahary Karadjov <github.com/zah>
* Jo De Boeck <github.com/grimpy> * Jo De Boeck <github.com/grimpy>
* Rudi Grinberg <github.com/rgrinberg>
* Timothy Mellor <github.com/mellort>
=============================================================================== ===============================================================================
CHANGELOG *ctrlp-changelog* CHANGELOG *ctrlp-changelog*

View file

@ -30,6 +30,7 @@ additional contributions from:
* [radicalbit](https://github.com/radicalbit) * [radicalbit](https://github.com/radicalbit)
* [redpill](https://github.com/redpill) * [redpill](https://github.com/redpill)
* [robhudson](https://github.com/robhudson) * [robhudson](https://github.com/robhudson)
* [Shraymonks](https://github.com/shraymonks)
* [sickill](https://github.com/sickill) * [sickill](https://github.com/sickill)
* [statik](https://github.com/statik) * [statik](https://github.com/statik)
* [steveno](https://github.com/steveno) * [steveno](https://github.com/steveno)

View file

@ -8,5 +8,5 @@
"vim-addon-mw-utils": {}, "vim-addon-mw-utils": {},
"tlib": {} "tlib": {}
}, },
"description" : "snipMate.vim aims to be a concise vim script that implements some of TextMate's snippets features in Vim. See README.markdown to learn about the features this fork adds" "description" : "snipMate.vim aims to be a concise vim script that implements some of TextMate's snippets features in Vim. See README.md to learn about the features this fork adds"
} }

View file

@ -7,7 +7,7 @@ let s:c = g:snipMate
try try
call tlib#input#List('mi', '', []) call tlib#input#List('mi', '', [])
catch /.*/ catch /.*/
echoe "you're missing tlib. See install instructions at ".expand('<sfile>:h:h').'/README.rst' echoe "you're missing tlib. See install instructions at ".expand('<sfile>:h:h').'/README.md'
endtry endtry
" match $ which doesn't follow a \ " match $ which doesn't follow a \
@ -121,8 +121,9 @@ endfunction
fun! s:ProcessSnippet(snip) fun! s:ProcessSnippet(snip)
let snippet = a:snip let snippet = a:snip
if exists('g:snipmate_content_visual') if exists('b:snipmate_content_visual')
let visual = g:snipmate_content_visual | unlet g:snipmate_content_visual let visual = b:snipmate_content_visual
unlet b:snipmate_content_visual
else else
let visual = '' let visual = ''
endif endif
@ -167,6 +168,18 @@ fun! s:ProcessSnippet(snip)
let i += 1 let i += 1
endw endw
" Add ${0} tab stop if found
if snippet =~ s:d . '{0'
let snippet = substitute(snippet, s:d.'{0', '${'.i, '')
let s = matchstr(snippet, s:d.'{'.i.':\zs.\{-}\ze}')
if s != ''
let snippet = substitute(snippet, s:d.'0', '$'.i, 'g')
let snippet = substitute(snippet, s:d.i, s.'&', 'g')
endif
else
let snippet .= '${'.i.'}'
endif
if &et " Expand tabs to spaces if 'expandtab' is set. if &et " Expand tabs to spaces if 'expandtab' is set.
return substitute(snippet, '\t', repeat(' ', &sts ? &sts : &sw), 'g') return substitute(snippet, '\t', repeat(' ', &sts ? &sts : &sw), 'g')
endif endif

View file

@ -1,309 +1,201 @@
*snipMate.txt* Plugin for using TextMate-style snippets in Vim. *SnipMate.txt* Plugin for using TextMate-style snippets in Vim.
snipMate *snippet* *snippets* *snipMate* SnipMate *snippet* *snippets* *SnipMate*
Last Change: December 27, 2009
|snipMate-installation| Installation 1. Description |SnipMate-description|
|snipMate-description| Description 2. Usage |SnipMate-usage|
|snipMate-related-work| Related work 3. Interface and Settings |SnipMate-interface| |SnipMate-settings|
|snipMate-usage| Usage (GETTING STARTED QUICKLY) 4. Snippet syntax |SnipMate-syntax|
|snipMate-snippet-sources| snippet sources 5. Snippet sources |SnipMate-snippet-sources|
|snipMate-syntax| Snippet syntax 6. Disadvantages to TextMate |SnipMate-disadvantages|
|snipMate-settings| Settings 7. Contact |SnipMate-contact|
|snipMate-features| Features 8. License |SnipMate-license|
|snipMate-disadvantages| Disadvantages to TextMate
|snipMate-contact| Contact
|snipMate-license| License
|snipMate-bugs| BUGS
For Vim version 7.0 or later. For Vim version 7.0 or later.
This plugin only works if 'compatible' is not set. This plugin only works if 'compatible' is not set.
{Vi does not have any of these features.} {Vi does not have any of these features.}
SnipMate depends on vim-addon-mw-utils and tlib.
============================================================================== ==============================================================================
INSTALLATION *snipMate-installation* DESCRIPTION *SnipMate-description*
Of course you can use whatever tool you want. SnipMate implements snippet features in Vim. A snippet is like a template,
However some features of snipMate depend on external VimL code: reducing repetitive insertion of pieces of text. Snippets can contain
tlib: tlib#input#List (providing a nice selection list) placeholders for modifying the text if necessary or interpolated code for
vim-addon-mw-utils: (providing all the caching implementation) evaluation. For example, in C, typing "for" then pushing <Tab> could expand
Thus i recommend vim-addon-manager to install snipMate because this will also to: >
fetch the dependencies for you.
The complete set of dependencies can be found in snipMate-addon-info.txt for (i = 0; i < count; i++) {
The current VAM-plugin name for this enhanced version of snipMate is "snipMate". /* code */
}
SnipMate is inspired by TextMate's snippet features.
============================================================================== ==============================================================================
DESCRIPTION *snipMate-description* USAGE *SnipMate-usage*
snipMate is an extension to Vim which allows you to store and retrieve text Every snippet consists of an expansion and a trigger. Typing a trigger into
snippets with placeholders in a very convenient way. your buffer and then hitting your trigger key (<Tab> by default, see
|SnipMate-mappings|) will replace the trigger with the expansion text.
snipMate is inspired by TextMate's snippet features. The expansion text can optionally include tab stops. When it does, upon
expansion of the snippet, the cursor is placed at the first one, and the user
can jump between each tab stop. Each of these tab stops can be represented by
default placeholder text. If such a placeholder is provided, then the text of
the placeholder can be repeated in the snippet at specified mirrors. Any edits
to the placeholder are instantly updated at every mirror.
SnipMate allows multiple snippets to use the same trigger. When triggered,
a list of all snippets with that trigger is provided and prompts for which
snippet to use.
*SnipMate-scopes*
SnipMate searches for snippets inside a directory named "snippets" inside each
entry in 'runtimepath'. Which files are loaded depends on 'filetype' and
'syntax'; see |SnipMate-syntax| for more information. Snippets are loaded and
refreshed automatically on demand.
Note: SnipMate does not ship with any snippets. In order to use it, the user
must either write their own snippets or obtain some from a repository like
https://github.com/honza/vim-snippets
============================================================================== ==============================================================================
RELATED WORK *snipMate-related-work* INTERFACE AND SETTINGS *SnipMate-interface* *SnipMate-settings*
There are some alternatives: *SnipMate-commands*
- ultisnips (python based) Commands~
- xptemplate which is probably a much more powerful
but also more complex
- neosnippets - which seems to be able to read snippet
files when swiching on compatible mode
- (..?)
snipmate is not perfect - however it gets its job done perfectly and gets out *:SnipMateOpenSnippetFiles*
of your way. So if you want to get started fast without reading too much :SnipMateOpenSnippetFiles Opens a list of all valid snippet locations
documentation probably snipmate is for you. based on the current scope |SnipMate-scopes|.
Only existing files and non-existing .snippets
files will be shown, with the existing files
shown first.
*SnipMate-options*
Options~
g:snips_author A variable used in some snippets in place of
the author's (your) name. Similar to
$TM_FULLNAME in TextMate. For example, >
snippet name
`g:snips_author`
< creates a snippet "name" that expands to your
name.
g:snipMate This |Dictionary| contains other SnipMate
options. In short add >
let g:snipMate = {}
< to your .vimrc before setting other SnipMate
options.
g:snipMate.scope_aliases A |Dictionary| associating certain filetypes
with other scopes |SnipMate-scopes|. The
entries consist of a filetype as the key and
a comma-separated list of aliases as the
value. For example, >
let g:snipMate.scope_aliases = {}
let g:snipMate.scope_aliases['ruby']
\ = 'ruby,ruby-rails'
< tells SnipMate that "ruby-rails" snippets in
addition to "ruby" snippets should be loaded
when editing files with 'filetype' set to
"ruby" or contains "ruby" as an entry in the
case of dotted filetypes.
g:snipMate['no_match_completion_feedkeys_chars']
A string inserted when no match for a trigger
is found. By default a tab is inserted
according to 'expandtab', 'tabstop', and
'softtabstop'. Set it to the empty string to
prevent anything from being inserted.
*SnipMate-mappings*
Mappings~
The mappings SnipMate uses can be customized with the |:map| commands. For
example, to change the key that triggers snippets and moves to the next
tabstop, >
:imap <C-J> <Plug>SnipMateNextOrTrigger
:smap <C-J> <Plug>SnipMateNextOrTrigger
The list of possible <Plug> mappings is as follows:
<Plug>SnipMateNextOrTrigger Default: <Tab> Mode: Insert, Select
Jumps to the next tab stop or, if none exists,
try to expand a snippet. Use in both insert
and select modes.
<Plug>SnipMateBack Default: <S-Tab> Mode: Insert, Select
Jump to the previous tab stop, if it exists.
Use in both insert and select modes.
<Plug>SnipMateShow Default: <C-R><Tab> Mode: Insert
Show all available snippets (that start with
the previous text, if it exists). Use in
insert mode.
<Plug>SnipMateVisual Default: <Tab> Mode: Visual
See |SnipMate-visual|.
Additionally, <CR> is mapped in visual mode in .snippets files for retabbing
snippets.
============================================================================== ==============================================================================
USAGE (GETTING STARTED QUICKLY) *snipMate-usage* SYNTAX *snippet-syntax* *SnipMate-syntax*
Adding snippets: > SnipMate looks inside of each entry of 'rtp' (or |SnipMate-snippet-sources|)
:SnipMateOpenSnippetFiles for a directory named /snippets/. Based on the 'filetype' and 'syntax'
< all valid snippet locations will be shown in a list. Existing files are settings (taking into account the dotted syntax), the following files are read
shown first. The list depends on Vim's |runtimepath|. Thus snipMate for snippets: >
perfectly integrates with the recommended way of installing each plugin into
its own directory which all newer plugin management solutions (VAM,
Pathogen, Vundle, ..) propagate.
The command will only show non existing .snippets files. See |snipMate-syntax| .../snippets/<scope>.snippets
to learn about all supported files snipMate can read. .../snippets/<scope>/<name>.snippets
.../snippets/<scope>/<trigger>.snippet
.../snippets/<scope>/<trigger>/<description>.snippet
In .snippets files you should use \t as indentation character which will where <scope> is an entry in 'filetype' or 'syntax', <name> is an arbitrary
be replaced by spaces/tabs depending on your Vim indentation settings. name, <trigger> is the trigger for a snippet, and <description> is
a description used for |SnipMate-multisnip|.
You can retab your snippet text by visually selecting it and pressing <cr>. A .snippet file defines a single snippet with the trigger (and description)
determined by the filename. The entire contents of the file are used as the
snippet expansion text.
Using snippets: ~ Multiple snippets can be defined in *.snippets files. Each snippet definition
looks something like: >
<c-r><tab>: shows a list of available snippets snippet trigger optional description
XX<tab> : will either show a list of all snippets starting with the guard left_from_cursor='^\s*'
characters XX or expand the snippet if it matches a snippet name. expanded text
more expanded text
associating snippets and filetypes: ~ < *SnipMate-multisnip*
The description is optional. If it is left out and a second snippet inside the
same .snippets file uses the same trigger, the second one will overwrite the
first. Otherwise multisnip is used.
1) > The guard condition line is also optional. It can be used to make a snippet
g:snipMate.scope_aliases available only in some cases. The value should be a VimL expression.
< defines which snippets types are available when you edit a buffer.
You can override the default in autoload/snipMate.vim in your .vimrc. For
example, to add both ruby.snippets and ruby-rails.snippets for files of
filetype='ruby', add the following to your vimrc: >
let g:snipMate = {}
let g:snipMate.scope_aliases = {}
let g:snipMate.scope_aliases['ruby'] = 'ruby,ruby-rails'
< SnipMate scopes are akin to filetypes. Setting a scope alias as shown above Note: Hard tabs in the expansion text are required. When the snippet is
allows multiple snippets files to be used for one filetype without actually expanded in the text and 'expandtab' is set, each tab will be replaced with
changing the filetype. spaces based on 'softtabstop' if nonzero or 'shiftwidth' otherwise.
2) Comments can be made in .snippets files by starting a line with a # character.
set filetype to a list such as 'html.javascript' or such. However these can't be used inside of snippet definitions: >
Add this to your .vimrc to not add tabs if there is no match: > # this is a correct comment
let g:snipMate['no_match_completion_feedkeys_chars'] = "" snippet trigger
< expanded text
snippet another_trigger
# this isn't a comment!
expanded text
*snipMate-disambiguation* This should hopefully be clear with the included syntax highlighting.
What happens if multiple files or filetypes define the same snippet name or if
|multi_snip| is being used? This results in name collisions!
You'll get list of matching snippets and can choose one.
Snippets are loaded and refreshed automatically on demand.
The parsed .snippets files are cached.
in the current buffer to show a list via.
==============================================================================
SNIPPET SOURCES *snipMate-snippet-sources*
snipMate is configurable.
plugin/snipMate.vim assigns three important keys:
>
" default implementation collecting snippets by handlers
let g:snipMate['get_snippets'] = snipMate#GetSnippets
" default handler:
let g:snipMateSources['default'] = snipMate#DefaultPool
" default directories containing snippets:
let g:snipMate['snippet_dirs'] = funcref#Function('return split(&runtimepath,",")')
<
You can override all of those settings.
You can see that the default set of snippets is determined by Vim's |rtp|.
Example 1: ~
autoload/snipMate_python_demo.vim shows how you can register additional
sources such as creating snippets on the fly representing python function
definitions found in the current file.
Example 2: ~
Add to your ~/.vimrc: For each know snippet add a second version ending in _
adding folding markers
>
let g:commentChar = {
\ 'vim': '"',
\ 'c': '//',
\ 'cpp': '//',
\ 'sh': '#',
\ 'python': '#'
\}
" url https://github.com/garbas/vim-snipmate/issues/49
fun! AddFolding(text)
return substitute(a:text,'\n'," ".g:commentChar[&ft]." {{{\n",1)."\n".g:commentChar[&ft]." }}}"
endf
fun! SnippetsWithFolding(scopes, trigger, result)
" hacky: temporarely remove this function to prevent infinite recursion:
call remove(g:snipMateSources, 'with_folding')
" get list of snippets:
let result = snipMate#GetSnippets(a:scopes, substitute(a:trigger,'_\(\*\)\?$','\1',''))
let g:snipMateSources['with_folding'] = funcref#Function('SnippetsWithFolding')
" add folding:
for k in keys(result)
let a:result[k.'_'] = map(result[k],'AddFolding(v:val)')
endfor
endf
" force setting default:
runtime plugin/snipMate.vim
" add our own source
let g:snipMateSources['with_folding'] = funcref#Function('SnippetsWithFolding')
<
More details about all possible relative locations to |rtp| can be found in
|snipMate-syntax|
==============================================================================
SYNTAX *snippet-syntax* *snipMate-syntax*
Default snippet sources [1], you can add your own as illustrated in
|snipMate-snippet-sources|.
trigger: the snippet's name.
|rtp| : Vim's |runtimepath| path list
one snippet per file:
|rtp|/snippets/<filetype>/<trigger>.snippet
many snippets per file, triggers are specified in file, see below:
|rtp|/snippets/<filetype>.snippets (RECOMMENDED)
|rtp|/snippets/<filetype>/*.snippets
See |snipMate-disambiguation| to learn about how name collisions are handled.
Note that dotted
'filetype' syntax is supported -- e.g., you can use >
:set ft=html.eruby syntax=sql
to activate snippets for both HTML, eRuby and sql for the current file.
See g:snipMate['get_scopes'] in plugin/snipMate.vim. However, this is not
recommended, as it can have unwanted side effects (appears to break some forms
of syntax highlighting). Instead, set g:snipMate.scope_aliases.
See|snipMate-usage|.
The syntax for snippets in *.snippets files is the following: >
snippet trigger
guard left_from_cursor='^\s*'
expanded text
more expanded text
Note: the guard condition line is optional. It can be used to make a snippet available
only in some cases. the value should be a viml expression.
(This implementation may change). Only supported in *.snippets files by now.
Multiple snippets having the same name but different triggers exist?
Note that the first hard tab after the snippet trigger is required, and not
expanded in the actual snippet. The syntax for *.snippet files is the same,
only without the trigger declaration and starting indentation.
Also note that indentation within snippets must be defined using hard tabs.
They can be expanded to spaces later if desired (see |snipMate-indenting|).
You can retab a snippet by visually selecting the lines, then press <cr>.
"#" is used as a line-comment character in *.snippets files; however, they can
only be used outside of a snippet declaration. E.g.: >
# this is a correct comment
snippet trigger
expanded text
snippet another_trigger
# this isn't a comment!
expanded text
<
This should hopefully be obvious with the included syntax highlighting.
*snipMate-${#}*
Tab stops ~
By default, the cursor is placed at the end of a snippet. To specify where the
cursor is to be placed next, use "${#}", where the # is the number of the tab
stop. E.g., to place the cursor first on the id of a <div> tag, and then allow
the user to press <tab> to go to the middle of it:
>
snippet div
<div id="${1}">
${2}
</div>
<
*snipMate-placeholders* *snipMate-${#:}* *snipMate-$#*
Placeholders ~
Placeholder text can be supplied using "${#:text}", where # is the number of
the tab stop. This text then can be copied throughout the snippet using "$#",
given # is the same number as used before. So, to make a C for loop: >
snippet for
for (${2:i}; $2 < ${1:count}; $1++) {
${4}
}
This will cause "count" to first be selected and change if the user starts
typing. When <tab> is pressed, the "i" in ${2}'s position will be selected;
all $2 variables will default to "i" and automatically be updated if the user
starts typing.
NOTE: "$#" syntax is used only for variables, not for tab stops as in TextMate.
Variables within variables are also possible. For instance: >
snippet opt
<option value="${1:option}">${2:$1}</option>
Will, as usual, cause "option" to first be selected and update all the $1
variables if the user starts typing. Since one of these variables is inside of
${2}, this text will then be used as a placeholder for the next tab stop,
allowing the user to change it if he wishes.
To copy a value throughout a snippet without supplying default text, simply
use the "${#:}" construct without the text; e.g.: >
snippet foo
${1:}bar$1
< *snipMate-commands*
*snipMate-visual-selection-support*
There is a special placeholder called {VISUAL}. If you visually select text,
then press <tab> Vim switches to insert mode. The next snippet you'll expand
will replace {VISUAL} by the text which was selected previously
Interpolated Vim Script ~
Snippets can also contain Vim script commands that are executed (via |eval()|)
when the snippet is inserted. Commands are given inside backticks (`...`); for
TextMates's functionality, use the |system()| function. E.g.: >
snippet date
`system("date +%Y-%m-%d")`
will insert the current date, assuming you are on a Unix system. Note that you
can also (and should) use |strftime()| for this example.
*snipMate-extends* *snipMate-extends*
Borrowing from UltiSnips, .snippets files can also contain an extends Borrowing from UltiSnips, .snippets files can also contain an extends
@ -313,11 +205,79 @@ directive, for example: >
will tell SnipMate to also read html, javascript, and css snippets. will tell SnipMate to also read html, javascript, and css snippets.
*SnipMate-tabstops*
Tab stops~
Filename([{expr}] [, {defaultText}]) *snipMate-filename* *Filename()* A tab stop, specified by ${#} where # is a number, tells SnipMate where to
position the cursor next. The special tab stop ${0} denotes the last cursor
position; in its absence, the cursor is placed at the end of the snippet.
For example, to place the cursor first on the id of a <div> tag, allow
the user to press <tab> to go to the middle of it, and finally end after
</div>: >
snippet div
<div id="${1}">
${2}
</div>
< *SnipMate-placeholders* *SnipMate-mirrors*
Placeholders and Mirrors~
Placeholder text can be supplied using "${#:text}", where # is the number of
the tab stop. This text then can be copied throughout the snippet using "$#",
given # is the same number as used before. So, to make a C for loop: >
snippet for
for (${2:i}; $2 < ${1:count}; $1++) {
${4}
}
This will cause "count" to first be selected and change if the user starts
typing. When <tab> is pressed, the "i" in ${2}'s position will be selected;
all $2 variables will default to "i" and automatically be updated if the user
starts typing.
NOTE: "$#" syntax is used only for mirrors, not for tab stops as in TextMate.
Mirrors can also be used inside of placeholders. For instance: >
snippet opt
<option value="${1:option}">${2:$1}</option>
Will, as usual, cause "option" to first be selected and update all the $1
variables if the user starts typing. Since one of these variables is inside of
${2}, this text will then be used as a placeholder for the next tab stop,
allowing the user to change it if he wishes.
To copy a value throughout a snippet without supplying default text, simply
use the "${#:}" construct without the text, e.g.: >
snippet foo
${1:}bar$1
< *SnipMate-visual*
There is a special placeholder called {VISUAL}. If you visually select text,
then press <Tab> Vim switches to insert mode. The next snippet you'll expand
will replace {VISUAL} by the text which was selected previously.
*SnipMate-eval*
Interpolated Vim Script~
Snippets can also contain Vim script commands that are executed (via |eval()|)
when the snippet is inserted. Commands are given inside backticks (`...`); for
TextMates's functionality, use the |system()| function. E.g.: >
snippet date
`system("date +%Y-%m-%d")`
will insert the current date, assuming you are on a Unix system. Note that you
can also (and should) use |strftime()| for this example.
Filename([{expr}] [, {defaultText}]) *SnipMate-Filename()*
Since the current filename is used often in snippets, a default function Since the current filename is used often in snippets, a default function
has been defined for it in snipMate.vim, appropriately called Filename(). has been defined for it in SnipMate.vim, appropriately called Filename().
With no arguments, the default filename without an extension is returned; With no arguments, the default filename without an extension is returned;
the first argument specifies what to place before or after the filename, the first argument specifies what to place before or after the filename,
@ -327,97 +287,88 @@ if you only want the filename to be returned, the first argument can be left
blank. Examples: > blank. Examples: >
snippet filename snippet filename
`Filename()` `Filename()`
snippet filename_with_default snippet filename_with_default
`Filename('', 'name')` `Filename('', 'name')`
snippet filename_foo snippet filename_foo
`filename('$1_foo')` `Filename('$1_foo')`
The first example returns the filename if it the file has been named, and an The first example returns the filename if it the file has been named, and an
empty string if it hasn't. The second returns the filename if it's been named, empty string if it hasn't. The second returns the filename if it's been named,
and "name" if it hasn't. The third returns the filename followed by "_foo" if and "name" if it hasn't. The third returns the filename followed by "_foo" if
it has been named, and an empty string if it hasn't. it has been named, and an empty string if it hasn't.
*multi_snip* ==============================================================================
To specify that a snippet can have multiple matches in a *.snippets file, use SNIPPET SOURCES *SnipMate-snippet-sources*
this syntax: >
snippet trigger A description of snippet #1 SnipMate is configurable.
expand this text
snippet trigger A description of snippet #2
expand THIS text!
See |snipMate-disambiguation| plugin/SnipMate.vim assigns three important keys: >
" default implementation collecting snippets by handlers
let g:SnipMate['get_snippets'] = SnipMate#GetSnippets
" default handler:
let g:SnipMateSources['default'] = SnipMate#DefaultPool
" default directories containing snippets:
let g:SnipMate['snippet_dirs']
\ = funcref#Function('return split(&runtimepath,",")')
You can override all of those settings.
You can see that the default set of snippets is determined by Vim's 'rtp'.
Example 1:~
autoload/SnipMate_python_demo.vim shows how you can register additional
sources such as creating snippets on the fly representing python function
definitions found in the current file.
Example 2:~
Add to your ~/.vimrc: For each know snippet add a second version ending in _
adding folding markers >
let g:commentChar = {
\ 'vim': '"',
\ 'c': '//',
\ 'cpp': '//',
\ 'sh': '#',
\ 'python': '#'
\ }
" url https://github.com/garbas/vim-snipmate/issues/49
fun! AddFolding(text)
return substitute(a:text,'\n'," ".g:commentChar[&ft]." {{{\n",1)."\n".g:commentChar[&ft]." }}}"
endf
fun! SnippetsWithFolding(scopes, trigger, result)
" hacky: temporarely remove this function to prevent infinite recursion:
call remove(g:SnipMateSources, 'with_folding')
" get list of snippets:
let result = SnipMate#GetSnippets(a:scopes, substitute(a:trigger,'_\(\*\)\?$','\1',''))
let g:SnipMateSources['with_folding'] = funcref#Function('SnippetsWithFolding')
" add folding:
for k in keys(result)
let a:result[k.'_'] = map(result[k],'AddFolding(v:val)')
endfor
endf
" force setting default:
runtime plugin/SnipMate.vim
" add our own source
let g:SnipMateSources['with_folding'] = funcref#Function('SnippetsWithFolding')
See |SnipMate-syntax| for more details about all possible relative locations
to 'rtp' can be found in.
============================================================================== ==============================================================================
SETTINGS *snipMate-settings* *g:snips_author* DISADVANTAGES *SnipMate-disadvantages*
The g:snips_author string (similar to $TM_FULLNAME in TextMate) should be set SnipMate.vim currently has the following disadvantages to TextMate's snippets:
to your name; it can then be used in snippets to automatically add it. E.g.: > - Nested placeholders are not currently possible. E.g.: >
'<div${1: id="${2:some_id}}">${3}</div>'
let g:snips_author = 'Hubert Farnsworth' < In TextMate this would first highlight ' id="some_id"', and if
snippet name
`g:snips_author`
<
*snipMate-expandtab* *snipMate-indenting*
If you would like your snippets to be expanded using spaces instead of tabs,
just enable 'expandtab' and set 'softtabstop' to your preferred amount of
spaces. If 'softtabstop' is not set, 'shiftwidth' is used instead.
*snipMate-mappings*
The mappings snipMate uses can be customized with the |:map| commands. For
example, to change the key that triggers snippets and moves to the next
tabstop, >
:imap <C-J> <Plug>snipMateNextOrTrigger
:smap <C-J> <Plug>snipMateNextOrTrigger
<
The list of possible <Plug> mappings is as follows:
<Plug>snipMateNextOrTrigger Jumps to the next tab stop or, if none exists,
try to expand a snippet. Use in both insert
and select modes.
<Plug>snipMateBack Jump to the previous tab stop, if it exists.
Use in both insert and select modes.
<Plug>snipMateShow Show all available snippets (that start with
the previous text, if it exists). Use in
insert mode.
<Plug>snipMateVisual |snipMate-visual-selection-support|
==============================================================================
FEATURES *snipMate-features*
snipMate.vim has the following features among others:
- The syntax of snippets is very similar to TextMate's, allowing
easy conversion.
- The position of the snippet is kept transparently (i.e. it does not use
markers/placeholders written to the buffer), which allows you to escape
out of an incomplete snippet, something particularly useful in Vim.
- Variables in snippets are updated as-you-type.
- Snippets can have multiple matches.
- Snippets can be out of order. For instance, in a do...while loop, the
condition can be added before the code.
- [New] File-based snippets are supported.
- [New] Triggers after non-word delimiters are expanded, e.g. "foo"
in "bar.foo".
- [New] <shift-tab> can now be used to jump tab stops in reverse order.
==============================================================================
DISADVANTAGES *snipMate-disadvantages*
snipMate.vim currently has the following disadvantages to TextMate's snippets:
- There is no $0; the order of tab stops must be explicitly stated.
- Placeholders within placeholders are not possible. E.g.: >
'<div${1: id="${2:some_id}}">${3}</div>'
<
In TextMate this would first highlight ' id="some_id"', and if
you hit delete it would automatically skip ${2} and go to ${3} you hit delete it would automatically skip ${2} and go to ${3}
on the next <tab>, but if you didn't delete it it would highlight on the next <tab>, but if you didn't delete it it would highlight
"some_id" first. You cannot do this in snipMate.vim. "some_id" first. You cannot do this in SnipMate.vim.
- Regex cannot be performed on variables, such as "${1/.*/\U&}" - Regex cannot be performed on variables, such as "${1/.*/\U&}"
- Placeholders cannot span multiple lines. - Placeholders cannot span multiple lines.
- Activating snippets in different scopes of the same file is - Activating snippets in different scopes of the same file is
@ -426,16 +377,7 @@ snipMate.vim currently has the following disadvantages to TextMate's snippets:
Perhaps some of these features will be added in a later release. Perhaps some of these features will be added in a later release.
============================================================================== ==============================================================================
CHANGELOG *snipMate-changelog* CHANGELOG *SnipMate-changelog*
0.86 - 2013-06-15
-----------------
* Use more idiomatic <Plug> maps
* Fix disappearing variables bug (hpesoj)
* Fix cursor position bug when a variable is on the same line as the stop
* Fix undo point creation causing problems with Supertab
* Fix bug where SnipMate would use a typed trigger as a regular expression
0.85 - 2013-04-03 0.85 - 2013-04-03
----------------- -----------------
@ -449,7 +391,7 @@ CHANGELOG *snipMate-changelog*
* Enable per-buffer expansion of snippets * Enable per-buffer expansion of snippets
* Fix 'cpo' compatibility * Fix 'cpo' compatibility
* Update supertab compatibility * Update supertab compatibility
* Enable customization of various things through g:snipMate * Enable customization of various things through g:SnipMate
* Disable spelling in snippet files * Disable spelling in snippet files
* Highlight trigger names in .snippets files * Highlight trigger names in .snippets files
@ -470,33 +412,24 @@ CHANGELOG *snipMate-changelog*
<http://www.vim.org/scripts/script.php?script_id=2540> <http://www.vim.org/scripts/script.php?script_id=2540>
============================================================================== ==============================================================================
CONTACT *snipMate-contact* *snipMate-author* CONTACT *SnipMate-contact* *SnipMate-author*
current maintainers: SnipMate is currently maintained by:
- Adnan Zafar - Rok Garbas
- garbas
- Marc Weber (marco-oweber@gmx.de) - Marc Weber (marco-oweber@gmx.de)
You should consider creating a github ticket or contacting us because the - Adnan Zafar
original author Michael Sanders did not act upon change requests for long
time. Anyway - he did most of the hard initial work.
To contact the author (Michael Sanders), please email: For bug reports, issues, or questions, check out the Issues page on GitHub:
msanders42+snipmate <at> gmail <dot> com https://github.com/garbas/vim-snipmate/issues
The original author, Michael Sanders, can be reached at:
msanders42+snipmate <at> gmail <dot> com
============================================================================== ==============================================================================
BUGS *snipMate-bugs* LICENSE *SnipMate-license*
<c-space> does not work: Try gvim. <c-space> is mapped to ctrl-2 or such in SnipMate is released under the MIT license:
Vim - this is not a snipmate issue.
[1]: I think having so many different ways is too complicated
- Marc Weber
==============================================================================
LICENSE *snipMate-license*
snipMate is released under the MIT license:
Copyright 2009-2010 Michael Sanders. All rights reserved. Copyright 2009-2010 Michael Sanders. All rights reserved.
@ -519,5 +452,4 @@ out of or in connection with the software or the use or other dealings in the
software. software.
============================================================================== ==============================================================================
vim:tw=78:ts=8:ft=help:norl:
vim:tw=78:ts=8:ft=help:norl:

View file

@ -21,7 +21,7 @@ set cpo&vim
try try
call funcref#Function('') call funcref#Function('')
catch /.*/ catch /.*/
echoe "you're missing vim-addon-mw-utils. See install instructions at ".expand('<sfile>:h:h').'/README.rst' echoe "you're missing vim-addon-mw-utils. See install instructions at ".expand('<sfile>:h:h').'/README.md'
endtry endtry
if (!exists('g:snipMateSources')) if (!exists('g:snipMateSources'))
@ -41,8 +41,7 @@ snoremap <silent> <Plug>snipMateNextOrTrigger <Esc>a<C-R>=snipMate#TriggerSnipp
inoremap <silent> <Plug>snipMateBack <C-R>=snipMate#BackwardsSnippet()<CR> inoremap <silent> <Plug>snipMateBack <C-R>=snipMate#BackwardsSnippet()<CR>
snoremap <silent> <Plug>snipMateBack <Esc>a<C-R>=snipMate#BackwardsSnippet()<CR> snoremap <silent> <Plug>snipMateBack <Esc>a<C-R>=snipMate#BackwardsSnippet()<CR>
inoremap <silent> <Plug>snipMateShow <C-R>=snipMate#ShowAvailableSnips()<CR> inoremap <silent> <Plug>snipMateShow <C-R>=snipMate#ShowAvailableSnips()<CR>
" FIXME: <Plug>snipMateVisual pollutes register(s) xnoremap <silent> <Plug>snipMateVisual :<C-U>call <SID>grab_visual()<CR>i
xnoremap <silent> <Plug>snipMateVisual s<C-O>:let g:snipmate_content_visual=getreg('1')<CR>
" config which can be overridden (shared lines) " config which can be overridden (shared lines)
if !exists('g:snipMate') if !exists('g:snipMate')
@ -76,6 +75,18 @@ fun! BackwardSnippet()
return snipMate#BackwardsSnippet() return snipMate#BackwardsSnippet()
endf endf
" Modified from Luc Hermitte's function on StackOverflow
" <http://stackoverflow.com/a/1534347>
function! s:grab_visual()
let a_save = @a
try
normal! gv"ad
let b:snipmate_content_visual = @a
finally
let @a = a_save
endtry
endfunction
" restore 'cpo' " restore 'cpo'
let &cpo = s:save_cpo let &cpo = s:save_cpo

View file

@ -27,46 +27,46 @@ endsnippet
snippet proto "Prototype (proto)" snippet proto "Prototype (proto)"
${1:class_name}.prototype.${2:method_name} = function(${3:first_argument}) ,,{ ${1:class_name}.prototype.${2:method_name} = function(${3:first_argument}) ,,{
${0:// body...} ${0}
}; }
endsnippet endsnippet
snippet for "for (...) {...} (faster)" snippet for "for (...) {...} (faster)"
for (var ${2:i} = ${1:Things}.length - 1; $2 >= 0; $2--){ for (var ${2:i} = ${1:Things}.length - 1; $2 >= 0; $2--){
${3:$1[$2]}$0 ${3:$1[$2]}$0
}; }
endsnippet endsnippet
snippet for "for (...) {...}" snippet for "for (...) {...}"
for (var ${2:i}=0; $2 < ${1:Things}.length; $2++) { for (var ${2:i}=0; $2 < ${1:Things}.length; $2++) {
${3:$1[$2]}$0 ${3:$1[$2]}$0
}; }
endsnippet endsnippet
snippet fun "function (fun)" snippet fun "function (fun)"
function ${1:function_name} (${2:argument}) { function ${1:function_name} (${2:argument}) {
${0:// body...} ${0}
} }
endsnippet endsnippet
# for one line if .. else you usually use a ? b : c # for one line if .. else you usually use a ? b : c
snippet ife "if ___ else" snippet ife "if ___ else"
if (${1}) { if (${1}) {
{$2} ${2}
} else { } else {
{$3} ${3}
}; }
endsnippet endsnippet
snippet if "if" snippet if "if"
if (${1}) { if (${1}) {
{$2} ${2}
}; }
endsnippet endsnippet
snippet timeout "setTimeout function" snippet timeout "setTimeout function"
setTimeout(function() {$0}${2:}, ${1:10}); setTimeout(function() {$0}${2:}, ${1:10})
endsnippet endsnippet
# vim:ft=snippets: # vim:ft=snippets:

View file

@ -1,258 +1,82 @@
## Snippets from SnipMate, taken from snippet <? "php open tag" b
## https://github.com/scrooloose/snipmate-snippets.git <?php
snippet array "array"
$${1:arrayName} = array('${2}' => ${3});${4}
endsnippet endsnippet
snippet def "def" snippet vdd "php var_dump and die"
define('${1}'${2});${3} var_dump(${1}); die();
endsnippet endsnippet
snippet do "do" snippet ns "php namespace" b
do { namespace ${1:`!p
${2} abspath = os.path.abspath(path)
} while (${1});" m = re.search(r'[A-Z].+(?=/)', abspath)
if m:
snip.rv = m.group().replace('/', '\\')
`};
endsnippet endsnippet
snippet doc_f "doc_f" snippet nc "php namespace and class" b
namespace ${1:`!p
abspath = os.path.abspath(path)
m = re.search(r'[A-Z].+(?=/)', abspath)
if m:
snip.rv = m.group().replace('/', '\\')
`};
/** /**
* $2 * ${3:@author `whoami`}${4}
* @return ${4:void} */
* @author ${5:`!v g:snips_author`} class ${2:`!p
**/ snip.rv = re.match(r'.*(?=\.)', fn).group()
${1:public }function ${2:someFunc}(${3}) `}
{${6} {
} }
endsnippet endsnippet
snippet doc_i "doc_i" snippet st "php static function" b
/** ${1:public} static function $2($3)
* $1 {
* @package ${2:default}
* @author ${3:`!v g:snips_author`}
**/
interface ${1:someClass}
{${4}
} // END interface $1"
endsnippet
snippet el "else"
else {
${1}
}
endsnippet
snippet for "for"
for ($${2:i} = 0; $$2 < ${1:count}; $$2${3:++}) {
${4} ${4}
} }
endsnippet endsnippet
snippet foreachk "foreachk" snippet __ "php constructor" b
foreach ($${1:variable} as $${2:key} => $${3:value}){ ${1:public} function __construct($2)
${4} {
${3}
} }
endsnippet endsnippet
snippet get "get" snippet sg "Setter and Getter" b
$_GET['${1}']${2}
/**
* @var ${3:`!p snip.rv = t[2].capitalize()`}${4}
*/
${1:protected} $$2;
public function set`!p snip.rv = t[2].capitalize()`(`!p
if re.match(r'[A-Z].*', t[3]):
snip.rv = t[3] + ' '
else:
snip.rv = ''
`$$2)
{
$this->$2 = $$2;
return $this;
}
public function get`!p snip.rv = t[2].capitalize()`()
{
return $this->$2;
}
endsnippet endsnippet
snippet if "if" snippet if "php if" !b
if (${1}) { if (${1}) {
${2} ${2}
} }
endsnippet endsnippet
snippet inc "inc"
include '${1:file}';${2}
endsnippet
snippet log "log"
error_log(var_export(${1}, true));${2}
endsnippet
snippet post "post"
$_POST['${1}']${2}
endsnippet
snippet req1 "req1"
require_once '${1:file}';${2}
endsnippet
snippet session "session"
$_SESSION['${1}']${2}
endsnippet
snippet t "t"
$${1:retVal} = (${2:condition}) ? ${3:a} : ${4:b};${5}
endsnippet
snippet var "var"
var_export(${1});${2}
endsnippet
snippet getter "PHP Class Getter" !b
/*
* Getter for $1
*/
public function get${1/\w+\s*/\u$0/}()
{
return $this->$1;$2
}
$4
endsnippet
snippet setter "PHP Class Setter" !b
/*
* Setter for $1
*/
public function set${1/\w+\s*/\u$0/}($$1)
{
$this->$1 = $$1;$3
${4:return $this;}
}
$0
endsnippet
snippet gs "PHP Class Getter Setter" !b
protected $$1
/*
* Getter for $1
*/
public function get${1/\w+\s*/\u$0/}()
{
return $this->$1;$2
}
/*
* Setter for $1
*/
public function set${1/\w+\s*/\u$0/}($$1)
{
$this->$1 = $$1;$3
${4:return $this;}
}
$0
endsnippet
snippet pub "Public function" !b
public function ${1:name}(${2:$param})
{
${VISUAL}${3:return null;}
}
$0
endsnippet
snippet pro "Protected function" !b
protected function ${1:name}(${2:$param})
{
${VISUAL}${3:return null;}
}
$0
endsnippet
snippet pri "Private function" !b
private function ${1:name}(${2:$param})
{
${VISUAL}${3:return null;}
}
$0
endsnippet
snippet pubs "Public static function" !b
public static function ${1:name}(${2:$param})
{
${VISUAL}${3:return null;}
}
$0
endsnippet
snippet pros "Protected static function" !b
protected static function ${1:name}(${2:$param})
{
${VISUAL}${3:return null;}
}
$0
endsnippet
snippet pris "Private static function" !b
private static function ${1:name}(${2:$param})
{
${VISUAL}${3:return null;}
}
$0
endsnippet
snippet fu "Function snip" !b
function ${1:name}(${2:$param})
{
${VISUAL}${3:return null;}
}
$0
endsnippet
# :vim:ft=snippets
snippet fore "Foreach loop"
foreach ($${1:variable} as $${3:value}){
${VISUAL}${4}
}
$0
endsnippet
snippet new "New class instance" !b
$$1 = new $1($2);
$0
endsnippet
snippet ife "if else"
if (${1:/* condition */}) {
${2}
} else {
${3}
}
$0
endsnippet
snippet class "Class declaration template" !b
/**
* Class ${1:`!p snip.rv=snip.fn.capitalize().split('.')[0]`}
* @author $2
*/
class $1
{
public function ${3:__construct}(${4:$options})
{
${4}
}
}
$0
endsnippet
snippet pr "Dumb debug helper in HTML"
echo '<pre>' . var_export($1, 1) . '</pre>';$0
endsnippet
snippet pc "Dumb debug helper in cli"
var_export($1);$0
endsnippet
# Symfony 2 based snippets
snippet sfa "Symfony 2 Controller action"
/**
* @Route("/${1:route_name}", name="$1")
* @Template()
*/
public function $1Action($2)
{
$3
return ${4:array();}$0
}
endsnippet
# :vim:ft=snippets:

View file

@ -0,0 +1,75 @@
snippet contr "symfony2 controller" b
namespace `!p
abspath = os.path.abspath(path)
m = re.search(r'[A-Z].+(?=/)', abspath)
if m:
snip.rv = m.group().replace('/', '\\')
`;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
/**
* ${1:@author `whoami`}${2}
*/
class `!p
snip.rv = re.match(r'.*(?=\.)', fn).group()
` extends Controller
{
}
endsnippet
snippet act "symfony2 action" b
/**
* @Route("${3}", name="${4}")
* @Method({${5:"GET"}})
* @Template()
*/
public function ${1}Action(${2})
{
${6}
return [];
}
endsnippet
snippet comm "symfony2 command" b
namespace `!p
abspath = os.path.abspath(path)
m = re.search(r'[A-Z].+(?=/)', abspath)
if m:
snip.rv = m.group().replace('/', '\\')
`;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
/**
* ${3:@author `whoami`}${4}
*/
class `!p
snip.rv = re.match(r'.*(?=\.)', fn).group()
` extends ContainerAwareCommand
{
protected function configure()
{
$this
->setName('${1}')
->setDescription('${2}')
->setDefinition([
new InputArgument('', InputArgument::REQUIRED, ''),
new InputOption('', null, InputOption::VALUE_NONE, ''),
])
;
}
protected function execute(InputInterface $input, OutputInterface $output)
{
}
}
endsnippet

View file

@ -89,6 +89,11 @@ snippet doc
snippet fn snippet fn
fn(${1:args}) -> ${2} end fn(${1:args}) -> ${2} end
snippet fun
function do
${1}
end
snippet mdoc snippet mdoc
@moduledoc """ @moduledoc """
${1} ${1}

View file

@ -103,6 +103,8 @@ snippet lipp
<%= link_to "${1:Link text...}", ${2:model}s_path %> <%= link_to "${1:Link text...}", ${2:model}s_path %>
snippet lt snippet lt
<%= link_to "${1:name}", ${2:dest} %> <%= link_to "${1:name}", ${2:dest} %>
snippet ntc
<%= number_to_currency(${1}) %>
snippet ofcfs snippet ofcfs
<%= options_from_collection_for_select ${1:collection}, ${2:value_method}, ${3:text_method}, ${4:selected_value} %> <%= options_from_collection_for_select ${1:collection}, ${2:value_method}, ${3:text_method}, ${4:selected_value} %>
snippet rf snippet rf

View file

@ -211,3 +211,11 @@ snippet t
# variable declaration # variable declaration
snippet v snippet v
var ${1:t} ${2:string} var ${1:t} ${2:string}
# goroutine named function
snippet g
go ${1:funcName}(${2})
# goroutine anonymous function
snippet ga
go func(${1} ${2:type}) {
${3:/* code */}
}(${4})

View file

@ -27,4 +27,5 @@ snippet ife
snippet ifp snippet ifp
- if ${1:condition}.presence? - if ${1:condition}.presence?
${2} ${2}
snippet ntc
= number_to_currency(${1})

View file

@ -6,8 +6,8 @@ snippet html5
<!doctype html> <!doctype html>
<html> <html>
<head> <head>
<meta charset="utf-8">
<title>$2</title> <title>$2</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
$3 $3
</head> </head>
<body> <body>
@ -34,15 +34,15 @@ snippet idn
snippet label_and_input snippet label_and_input
<label for="${2:$1}">${1}</label> <label for="${2:$1}">${1}</label>
<input type="${3:text}" name="${4:$2}" id="${5:$2}" value="${6}" />${7} <input type="${3:text}" name="${4:$2}" id="${5:$2}" value="${6}">${7}
# FORMS # FORMS
# use idn . or n to add id # use idn . or n to add id
snippet input snippet input
<input type="${1:text}" value="${2}" ${3}/>${7} <input type="${1:text}" value="${2}" ${3}>${7}
snippet submit snippet submit
<input type="submit" value="${2}" ${3}/>${7} <input type="submit" value="${2}" ${3}>${7}
snippet textarea snippet textarea
<textarea $1>$2</textarea> <textarea $1>$2</textarea>
@ -61,7 +61,7 @@ snippet img
<img src="$1" alt="$2"/> <img src="$1" alt="$2"/>
# JS/CSS # JS/CSS
snippet css_file snippet css_file
<link rel="stylesheet" href="${1:style.css}" type="text/css" media="${2:all}" />${3} <link rel="stylesheet" href="${1:style.css}" type="text/css" media="${2:all}">${3}
snippet css_block snippet css_block
<link rel="stylesheet" href="${1:style.css}" type="text/css" media="${2:all}"> <link rel="stylesheet" href="${1:style.css}" type="text/css" media="${2:all}">
</link> </link>

View file

@ -0,0 +1,30 @@
snippet .attr
.attr("${1}", ${2})
snippet .style
.style("${1}", ${2})
snippet axis
d3.svg.axis()
.orient(${1})
.scale(${2})
snippet fd
function(d) { ${1} }
snippet fdi
function(d, i) { ${1} }
snippet marginconvention
var ${1:margin} = { top: ${2:10}, right: ${3:10}, bottom: ${4:10}, left: ${5:10} };
var ${6:width} = ${7:970} - $1.left - $1.right;
var ${8:height} = ${9:500} - $1.top - $1.bottom;
var ${10:svg} = d3.select("${11}").append("svg")
.attr("width", $6)
.attr("height", $8)
.append("g")
.attr("transform", "translate(" + $1.left + "," + $1.top + ")")
snippet nest
d3.nest()
.key(${1})
.entries(${2})
snippet scale
d3.scale.linear()
.domain(${1})
.range(${2})

View file

@ -185,3 +185,15 @@ snippet lc
logger.critical(${1:msg}) logger.critical(${1:msg})
snippet li snippet li
logger.info(${1:msg}) logger.info(${1:msg})
snippet epydoc
"""
${1:Description}
@param ${2:param}: ${3: Description}
@type $2: ${4: Type}
@return: ${5: Description}
@rtype : ${6: Type}
@raise e: ${7: Description}
"""