diff --git a/after/plugin/snipMate.vim b/after/plugin/snipMate.vim new file mode 100644 index 0000000..03e79ae --- /dev/null +++ b/after/plugin/snipMate.vim @@ -0,0 +1,35 @@ +" These are the mappings for snipMate.vim. Putting it here ensures that it +" will be mapped after other plugins such as supertab.vim. +if !exists('loaded_snips') || exists('s:did_snips_mappings') + finish +endif +let s:did_snips_mappings = 1 + +ino =TriggerSnippet() +snor i=TriggerSnippet() +ino =BackwardsSnippet() +snor i=BackwardsSnippet() +ino =ShowAvailableSnips() + +" The default mappings for these are annoying & sometimes break snipMate. +" You can change them back if you want, I've put them here for convenience. +snor b +snor a +snor bi +snor ' b' +snor ` b` +snor % b% +snor U bU +snor ^ b^ +snor \ b\ +snor b + +" By default load snippets in snippets_dir +if empty(snippets_dir) + finish +endif + +call GetSnippets(snippets_dir, '_') " Get global snippets + +au FileType * if &ft != 'help' | call GetSnippets(snippets_dir, &ft) | endif +" vim:noet:sw=4:ts=4:ft=vim diff --git a/autoload/snipMate.vim b/autoload/snipMate.vim new file mode 100644 index 0000000..dcd28f6 --- /dev/null +++ b/autoload/snipMate.vim @@ -0,0 +1,433 @@ +fun! Filename(...) + let filename = expand('%:t:r') + if filename == '' | return a:0 == 2 ? a:2 : '' | endif + return !a:0 || a:1 == '' ? filename : substitute(a:1, '$1', filename, 'g') +endf + +fun s:RemoveSnippet() + unl! g:snipPos s:curPos s:snipLen s:endCol s:endLine s:prevLen + \ s:lastBuf s:oldWord + if exists('s:update') + unl s:startCol s:origWordLen s:update + if exists('s:oldVars') | unl s:oldVars s:oldEndCol | endif + endif + aug! snipMateAutocmds +endf + +fun snipMate#expandSnip(snip, col) + let lnum = line('.') | let col = a:col + + let snippet = s:ProcessSnippet(a:snip) + " Avoid error if eval evaluates to nothing + if snippet == '' | return '' | endif + + " Expand snippet onto current position with the tab stops removed + let snipLines = split(substitute(snippet, '$\d\+\|${\d\+.\{-}}', '', 'g'), "\n", 1) + + let line = getline(lnum) + let afterCursor = strpart(line, col - 1) + " Keep text after the cursor + if afterCursor != "\t" && afterCursor != ' ' + let line = strpart(line, 0, col - 1) + let snipLines[-1] .= afterCursor + else + let afterCursor = '' + " For some reason the cursor needs to move one right after this + if line != '' && col == 1 && &ve != 'all' && &ve != 'onemore' + let col += 1 + endif + endif + + call setline(lnum, line.snipLines[0]) + + " Autoindent snippet according to previous indentation + let indent = matchend(line, '^.\{-}\ze\(\S\|$\)') + 1 + call append(lnum, map(snipLines[1:], "'".strpart(line, 0, indent - 1)."'.v:val")) + + " Open any folds snippet expands into + if &fen | sil! exe lnum.','.(lnum + len(snipLines) - 1).'foldopen' | endif + + let [g:snipPos, s:snipLen] = s:BuildTabStops(snippet, lnum, col - indent, indent) + + if s:snipLen + aug snipMateAutocmds + au CursorMovedI * call s:UpdateChangedSnip(0) + au InsertEnter * call s:UpdateChangedSnip(1) + aug END + let s:lastBuf = bufnr(0) " Only expand snippet while in current buffer + let s:curPos = 0 + let s:endCol = g:snipPos[s:curPos][1] + let s:endLine = g:snipPos[s:curPos][0] + + call cursor(g:snipPos[s:curPos][0], g:snipPos[s:curPos][1]) + let s:prevLen = [line('$'), col('$')] + if g:snipPos[s:curPos][2] != -1 | return s:SelectWord() | endif + else + unl g:snipPos s:snipLen + " Place cursor at end of snippet if no tab stop is given + let newlines = len(snipLines) - 1 + call cursor(lnum + newlines, indent + len(snipLines[-1]) - len(afterCursor) + \ + (newlines ? 0: col - 1)) + endif + return '' +endf + +" Prepare snippet to be processed by s:BuildTabStops +fun s:ProcessSnippet(snip) + let snippet = a:snip + " Evaluate eval (`...`) expressions. + " Using a loop here instead of a regex fixes a bug with nested "\=". + if stridx(snippet, '`') != -1 + while match(snippet, '`.\{-}`') != -1 + let snippet = substitute(snippet, '`.\{-}`', + \ substitute(eval(matchstr(snippet, '`\zs.\{-}\ze`')), + \ "\n\\%$", '', ''), '') + endw + let snippet = substitute(snippet, "\r", "\n", 'g') + endif + + " Place all text after a colon in a tab stop after the tab stop + " (e.g. "${#:foo}" becomes "${:foo}foo"). + " This helps tell the position of the tab stops later. + let snippet = substitute(snippet, '${\d\+:\(.\{-}\)}', '&\1', 'g') + + " Update the a:snip so that all the $# become the text after + " the colon in their associated ${#}. + " (e.g. "${1:foo}" turns all "$1"'s into "foo") + let i = 1 + while stridx(snippet, '${'.i) != -1 + let s = matchstr(snippet, '${'.i.':\zs.\{-}\ze}') + if s != '' + let snippet = substitute(snippet, '$'.i, s.'&', 'g') + endif + let i += 1 + endw + + if &et " Expand tabs to spaces if 'expandtab' is set. + return substitute(snippet, '\t', repeat(' ', &sts ? &sts : &sw), 'g') + endif + return snippet +endf + +" Counts occurences of haystack in needle +fun s:Count(haystack, needle) + let counter = 0 + let index = stridx(a:haystack, a:needle) + while index != -1 + let index = stridx(a:haystack, a:needle, index+1) + let counter += 1 + endw + return counter +endf + +" Builds a list of a list of each tab stop in the snippet containing: +" 1.) The tab stop's line number. +" 2.) The tab stop's column number +" (by getting the length of the string between the last "\n" and the +" tab stop). +" 3.) The length of the text after the colon for the current tab stop +" (e.g. "${1:foo}" would return 3). If there is no text, -1 is returned. +" 4.) If the "${#:}" construct is given, another list containing all +" the matches of "$#", to be replaced with the placeholder. This list is +" composed the same way as the parent; the first item is the line number, +" and the second is the column. +fun s:BuildTabStops(snip, lnum, col, indent) + let snipPos = [] + let i = 1 + let withoutVars = substitute(a:snip, '$\d\+', '', 'g') + while stridx(a:snip, '${'.i) != -1 + let beforeTabStop = matchstr(withoutVars, '^.*\ze${'.i.'\D') + let withoutOthers = substitute(withoutVars, '${\('.i.'\D\)\@!\d\+.\{-}}', '', 'g') + + let j = i - 1 + call add(snipPos, [0, 0, -1]) + let snipPos[j][0] = a:lnum + s:Count(beforeTabStop, "\n") + let snipPos[j][1] = a:indent + len(matchstr(withoutOthers, '.*\(\n\|^\)\zs.*\ze${'.i.'\D')) + if snipPos[j][0] == a:lnum | let snipPos[j][1] += a:col | endif + + " Get all $# matches in another list, if ${#:name} is given + if stridx(withoutVars, '${'.i.':') != -1 + let snipPos[j][2] = len(matchstr(withoutVars, '${'.i.':\zs.\{-}\ze}')) + let dots = repeat('.', snipPos[j][2]) + call add(snipPos[j], []) + let withoutOthers = substitute(a:snip, '${\d\+.\{-}}\|$'.i.'\@!\d\+', '', 'g') + while match(withoutOthers, '$'.i.'\(\D\|$\)') != -1 + let beforeMark = matchstr(withoutOthers, '^.\{-}\ze'.dots.'$'.i.'\(\D\|$\)') + call add(snipPos[j][3], [0, 0]) + let snipPos[j][3][-1][0] = a:lnum + s:Count(beforeMark, "\n") + let snipPos[j][3][-1][1] = a:indent + (snipPos[j][3][-1][0] > a:lnum + \ ? len(matchstr(beforeMark, '.*\n\zs.*')) + \ : a:col + len(beforeMark)) + let withoutOthers = substitute(withoutOthers, '$'.i.'\ze\(\D\|$\)', '', '') + endw + endif + let i += 1 + endw + return [snipPos, i - 1] +endf + +fun snipMate#jumpTabStop(backwards) + let leftPlaceholder = exists('s:origWordLen') + \ && s:origWordLen != g:snipPos[s:curPos][2] + if leftPlaceholder && exists('s:oldEndCol') + let startPlaceholder = s:oldEndCol + 1 + endif + + if exists('s:update') + call s:UpdatePlaceholderTabStops() + else + call s:UpdateTabStops() + endif + + " Don't reselect placeholder if it has been modified + if leftPlaceholder && g:snipPos[s:curPos][2] != -1 + if exists('startPlaceholder') + let g:snipPos[s:curPos][1] = startPlaceholder + else + let g:snipPos[s:curPos][1] = col('.') + let g:snipPos[s:curPos][2] = 0 + endif + endif + + let s:curPos += a:backwards ? -1 : 1 + " Loop over the snippet when going backwards from the beginning + if s:curPos < 0 | let s:curPos = s:snipLen - 1 | endif + + if s:curPos == s:snipLen + let sMode = s:endCol == g:snipPos[s:curPos-1][1]+g:snipPos[s:curPos-1][2] + call s:RemoveSnippet() + return sMode ? "\" : TriggerSnippet() + endif + + call cursor(g:snipPos[s:curPos][0], g:snipPos[s:curPos][1]) + + let s:endLine = g:snipPos[s:curPos][0] + let s:endCol = g:snipPos[s:curPos][1] + let s:prevLen = [line('$'), col('$')] + + return g:snipPos[s:curPos][2] == -1 ? '' : s:SelectWord() +endf + +fun s:UpdatePlaceholderTabStops() + let changeLen = s:origWordLen - g:snipPos[s:curPos][2] + unl s:startCol s:origWordLen s:update + if !exists('s:oldVars') | return | endif + " Update tab stops in snippet if text has been added via "$#" + " (e.g., in "${1:foo}bar$1${2}"). + if changeLen != 0 + let curLine = line('.') + + for pos in g:snipPos + if pos == g:snipPos[s:curPos] | continue | endif + let changed = pos[0] == curLine && pos[1] > s:oldEndCol + let changedVars = 0 + let endPlaceholder = pos[2] - 1 + pos[1] + " Subtract changeLen from each tab stop that was after any of + " the current tab stop's placeholders. + for [lnum, col] in s:oldVars + if lnum > pos[0] | break | endif + if pos[0] == lnum + if pos[1] > col || (pos[2] == -1 && pos[1] == col) + let changed += 1 + elseif col < endPlaceholder + let changedVars += 1 + endif + endif + endfor + let pos[1] -= changeLen * changed + let pos[2] -= changeLen * changedVars " Parse variables within placeholders + " e.g., "${1:foo} ${2:$1bar}" + + if pos[2] == -1 | continue | endif + " Do the same to any placeholders in the other tab stops. + for nPos in pos[3] + let changed = nPos[0] == curLine && nPos[1] > s:oldEndCol + for [lnum, col] in s:oldVars + if lnum > nPos[0] | break | endif + if nPos[0] == lnum && nPos[1] > col + let changed += 1 + endif + endfor + let nPos[1] -= changeLen * changed + endfor + endfor + endif + unl s:endCol s:oldVars s:oldEndCol +endf + +fun s:UpdateTabStops() + let changeLine = s:endLine - g:snipPos[s:curPos][0] + let changeCol = s:endCol - g:snipPos[s:curPos][1] + if exists('s:origWordLen') + let changeCol -= s:origWordLen + unl s:origWordLen + endif + let lnum = g:snipPos[s:curPos][0] + let col = g:snipPos[s:curPos][1] + " Update the line number of all proceeding tab stops if has + " been inserted. + if changeLine != 0 + let changeLine -= 1 + for pos in g:snipPos + if pos[0] >= lnum + if pos[0] == lnum | let pos[1] += changeCol | endif + let pos[0] += changeLine + endif + if pos[2] == -1 | continue | endif + for nPos in pos[3] + if nPos[0] >= lnum + if nPos[0] == lnum | let nPos[1] += changeCol | endif + let nPos[0] += changeLine + endif + endfor + endfor + elseif changeCol != 0 + " Update the column of all proceeding tab stops if text has + " been inserted/deleted in the current line. + for pos in g:snipPos + if pos[1] >= col && pos[0] == lnum + let pos[1] += changeCol + endif + if pos[2] == -1 | continue | endif + for nPos in pos[3] + if nPos[0] > lnum | break | endif + if nPos[0] == lnum && nPos[1] >= col + let nPos[1] += changeCol + endif + endfor + endfor + endif +endf + +fun s:SelectWord() + let s:origWordLen = g:snipPos[s:curPos][2] + let s:oldWord = strpart(getline('.'), g:snipPos[s:curPos][1] - 1, + \ s:origWordLen) + let s:prevLen[1] -= s:origWordLen + if !empty(g:snipPos[s:curPos][3]) + let s:update = 1 + let s:endCol = -1 + let s:startCol = g:snipPos[s:curPos][1] - 1 + endif + if !s:origWordLen | return '' | endif + let l = col('.') != 1 ? 'l' : '' + if &sel == 'exclusive' + return "\".l.'v'.s:origWordLen."l\" + endif + return s:origWordLen == 1 ? "\".l.'gh' + \ : "\".l.'v'.(s:origWordLen - 1)."l\" +endf + +" This updates the snippet as you type when text needs to be inserted +" into multiple places (e.g. in "${1:default text}foo$1bar$1", +" "default text" would be highlighted, and if the user types something, +" UpdateChangedSnip() would be called so that the text after "foo" & "bar" +" are updated accordingly) +" +" It also automatically quits the snippet if the cursor is moved out of it +" while in insert mode. +fun s:UpdateChangedSnip(entering) + if exists('g:snipPos') && bufnr(0) != s:lastBuf + call s:RemoveSnippet() + elseif exists('s:update') " If modifying a placeholder + if !exists('s:oldVars') && s:curPos + 1 < s:snipLen + " Save the old snippet & word length before it's updated + " s:startCol must be saved too, in case text is added + " before the snippet (e.g. in "foo$1${2}bar${1:foo}"). + let s:oldEndCol = s:startCol + let s:oldVars = deepcopy(g:snipPos[s:curPos][3]) + endif + let col = col('.') - 1 + + if s:endCol != -1 + let changeLen = col('$') - s:prevLen[1] + let s:endCol += changeLen + else " When being updated the first time, after leaving select mode + if a:entering | return | endif + let s:endCol = col - 1 + endif + + " If the cursor moves outside the snippet, quit it + if line('.') != g:snipPos[s:curPos][0] || col < s:startCol || + \ col - 1 > s:endCol + unl! s:startCol s:origWordLen s:oldVars s:update + return s:RemoveSnippet() + endif + + call s:UpdateVars() + let s:prevLen[1] = col('$') + elseif exists('g:snipPos') + if !a:entering && g:snipPos[s:curPos][2] != -1 + let g:snipPos[s:curPos][2] = -2 + endif + + let col = col('.') + let lnum = line('.') + let changeLine = line('$') - s:prevLen[0] + + if lnum == s:endLine + let s:endCol += col('$') - s:prevLen[1] + let s:prevLen = [line('$'), col('$')] + endif + if changeLine != 0 + let s:endLine += changeLine + let s:endCol = col + endif + + " Delete snippet if cursor moves out of it in insert mode + if (lnum == s:endLine && (col > s:endCol || col < g:snipPos[s:curPos][1])) + \ || lnum > s:endLine || lnum < g:snipPos[s:curPos][0] + call s:RemoveSnippet() + endif + endif +endf + +" This updates the variables in a snippet when a placeholder has been edited. +" (e.g., each "$1" in "${1:foo} $1bar $1bar") +fun s:UpdateVars() + let newWordLen = s:endCol - s:startCol + 1 + let newWord = strpart(getline('.'), s:startCol, newWordLen) + if newWord == s:oldWord || empty(g:snipPos[s:curPos][3]) + return + endif + + let changeLen = g:snipPos[s:curPos][2] - newWordLen + let curLine = line('.') + let startCol = col('.') + let oldStartSnip = s:startCol + let updateTabStops = changeLen != 0 + let i = 0 + + for [lnum, col] in g:snipPos[s:curPos][3] + if updateTabStops + let start = s:startCol + if lnum == curLine && col <= start + let s:startCol -= changeLen + let s:endCol -= changeLen + endif + for nPos in g:snipPos[s:curPos][3][(i):] + " This list is in ascending order, so quit if we've gone too far. + if nPos[0] > lnum | break | endif + if nPos[0] == lnum && nPos[1] > col + let nPos[1] -= changeLen + endif + endfor + if lnum == curLine && col > start + let col -= changeLen + let g:snipPos[s:curPos][3][i][1] = col + endif + let i += 1 + endif + + " "Very nomagic" is used here to allow special characters. + call setline(lnum, substitute(getline(lnum), '\%'.col.'c\V'. + \ escape(s:oldWord, '\'), escape(newWord, '\&'), '')) + endfor + if oldStartSnip != s:startCol + call cursor(0, startCol + s:startCol - oldStartSnip) + endif + + let s:oldWord = newWord + let g:snipPos[s:curPos][2] = newWordLen +endf +" vim:noet:sw=4:ts=4:ft=vim diff --git a/doc/snipMate.txt b/doc/snipMate.txt new file mode 100644 index 0000000..704d44a --- /dev/null +++ b/doc/snipMate.txt @@ -0,0 +1,286 @@ +*snipMate.txt* Plugin for using TextMate-style snippets in Vim. + +snipMate *snippet* *snippets* *snipMate* +Last Change: July 13, 2009 + +|snipMate-description| Description +|snipMate-syntax| Snippet syntax +|snipMate-usage| Usage +|snipMate-settings| Settings +|snipMate-features| Features +|snipMate-disadvantages| Disadvantages to TextMate +|snipMate-contact| Contact + +For Vim version 7.0 or later. +This plugin only works if 'compatible' is not set. +{Vi does not have any of these features.} + +============================================================================== +DESCRIPTION *snipMate-description* + +snipMate.vim implements some of TextMate's snippets features in Vim. A +snippet is a piece of often-typed text that you can insert into your +document using a trigger word followed by a . + +For instance, in a C file using the default installation of snipMate.vim, if +you type "for" in insert mode, it will expand a typical for loop in C: > + + for (i = 0; i < count; i++) { + + } + + +To go to the next item in the loop, simply over to it; if there is +repeated code, such as the "i" variable in this example, you can simply +start typing once it's highlighted and all the matches specified in the +snippet will be updated. To go in reverse, use . + +============================================================================== +SYNTAX *snippet-syntax* + +Snippets can be defined in two ways. They can be in their own file, named +after their trigger in 'snippets//.snippet', or they can be +defined together in a 'snippets/.snippets' file. Note that dotted +'filetype' syntax is supported -- e.g., you can use > + + :set ft=html.eruby + +to activate snippets for both HTML and eRuby for the current file. + +The syntax for snippets in *.snippets files is the following: > + + snippet trigger + expanded text + more expanded text + +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 snippets must be defined using hard tabs. They can be expanded +to spaces later if desired (see |snipMate-indenting|). + +"#" 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
tag, and then allow +the user to press to go to the middle of it: + > + snippet div +
+ ${2} +
+< + *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 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 + + +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* +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* *Filename()* + +Since the current filename is used often in snippets, a default function +has been defined for it in snipMate.vim, appropriately called Filename(). + +With no arguments, the default filename without an extension is returned; +the first argument specifies what to place before or after the filename, +and the second argument supplies the default text to be used if the file +has not been named. "$1" in the first argument is replaced with the filename; +if you only want the filename to be returned, the first argument can be left +blank. Examples: > + + snippet filename + `Filename()` + snippet filename_with_default + `Filename('', 'name')` + snippet filename_foo + `filename('$1_foo')` + +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, +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. + + *multi_snip* +To specify that a snippet can have multiple matches in a *.snippets file, use +this syntax: > + + snippet trigger A description of snippet #1 + expand this text + snippet trigger A description of snippet #2 + expand THIS text! + +In this example, when "trigger" is typed, a numbered menu containing all +of the descriptions of the "trigger" will be shown; when the user presses the +corresponding number, that snippet will then be expanded. + +To create a snippet with multiple matches using *.snippet files, +simply place all the snippets in a subdirectory with the trigger name: +'snippets///.snippet'. + +============================================================================== +USAGE *snipMate-usage* + + *'snippets'* *g:snippets_dir* +Snippets are by default looked for any 'snippets' directory in your +'runtimepath'. Typically, it is located at '~/.vim/snippets/' on *nix or +'$HOME\vimfiles\snippets\' on Windows. To change that location or add another +one, change the g:snippets_dir variable in your |.vimrc| to your preferred +directory, or use the |ExtractSnips()|function. This will be used by the +|globpath()| function, and so accepts the same syntax as it (e.g., +comma-separated paths). + +ExtractSnipsFile({directory}, {filetype}) *ExtractSnipsFile()* *.snippets* + +ExtractSnipsFile() extracts the specified *.snippets file for the given +filetype. A .snippets file contains multiple snippet declarations for the +filetype. It is further explained above, in |snippet-syntax|. + +ExtractSnips({directory}, {filetype}) *ExtractSnips()* *.snippet* + +ExtractSnips() extracts *.snippet files from the specified directory and +defines them as snippets for the given filetype. The directory tree should +look like this: 'snippets//.snippet'. If the snippet has +multiple matches, it should look like this: +'snippets///.snippet' (see |multi_snip|). + + *ResetSnippets()* +The ResetSnippets() function removes all snippets from memory. This is useful +to put at the top of a snippet setup file for if you would like to |:source| +it multiple times. + + *list-snippets* *i_CTRL-R_* +If you would like to see what snippets are available, simply type +in the current buffer to show a list via |popupmenu-completion|. + +============================================================================== +SETTINGS *snipMate-settings* *g:snips_author* + +The g:snips_author string (similar to $TM_FULLNAME in TextMate) should be set +to your name; it can then be used in snippets to automatically add it. E.g.: > + + let g:snips_author = 'Hubert Farnsworth' + 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-remap* +snipMate does not come with a setting to customize the trigger key, but you +can remap it easily in the two lines it's defined in the 'after' directory +under 'plugin/snipMate.vim'. For instance, to change the trigger key +to CTRL-J, just change this: > + + ino =TriggerSnippet() + snor i=TriggerSnippet() + +to this: > + ino =TriggerSnippet() + snor i=TriggerSnippet() + +============================================================================== +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] 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.: > + + '${3}
' +< + In TextMate this would first highlight ' id="some_id"', and if + you hit delete it would automatically skip ${2} and go to ${3} + on the next , but if you didn't delete it it would highlight + "some_id" first. You cannot do this in snipMate.vim. + - Regex cannot be performed on variables, such as "${1/.*/\U&}" + - Placeholders cannot span multiple lines. + - Activating snippets in different scopes of the same file is + not possible. + +Perhaps some of these features will be added in a later release. + +============================================================================== +CONTACT *snipMate-contact* *snipMate-author* + +To contact the author (Michael Sanders), please email: + msanders42+snipmate gmail com + +I greatly appreciate any suggestions or improvements offered for the script. + +============================================================================== + +vim:tw=78:ts=8:ft=help:norl: diff --git a/doc/tags b/doc/tags new file mode 100644 index 0000000..b21f751 --- /dev/null +++ b/doc/tags @@ -0,0 +1,33 @@ +'snippets' snipMate.txt /*'snippets'* +.snippet snipMate.txt /*.snippet* +.snippets snipMate.txt /*.snippets* +ExtractSnips() snipMate.txt /*ExtractSnips()* +ExtractSnipsFile() snipMate.txt /*ExtractSnipsFile()* +Filename() snipMate.txt /*Filename()* +ResetSnippets() snipMate.txt /*ResetSnippets()* +g:snippets_dir snipMate.txt /*g:snippets_dir* +g:snips_author snipMate.txt /*g:snips_author* +i_CTRL-R_ snipMate.txt /*i_CTRL-R_* +list-snippets snipMate.txt /*list-snippets* +multi_snip snipMate.txt /*multi_snip* +snipMate snipMate.txt /*snipMate* +snipMate-$# snipMate.txt /*snipMate-$#* +snipMate-${#:} snipMate.txt /*snipMate-${#:}* +snipMate-${#} snipMate.txt /*snipMate-${#}* +snipMate-author snipMate.txt /*snipMate-author* +snipMate-commands snipMate.txt /*snipMate-commands* +snipMate-contact snipMate.txt /*snipMate-contact* +snipMate-description snipMate.txt /*snipMate-description* +snipMate-disadvantages snipMate.txt /*snipMate-disadvantages* +snipMate-expandtab snipMate.txt /*snipMate-expandtab* +snipMate-features snipMate.txt /*snipMate-features* +snipMate-filename snipMate.txt /*snipMate-filename* +snipMate-indenting snipMate.txt /*snipMate-indenting* +snipMate-placeholders snipMate.txt /*snipMate-placeholders* +snipMate-remap snipMate.txt /*snipMate-remap* +snipMate-settings snipMate.txt /*snipMate-settings* +snipMate-usage snipMate.txt /*snipMate-usage* +snipMate.txt snipMate.txt /*snipMate.txt* +snippet snipMate.txt /*snippet* +snippet-syntax snipMate.txt /*snippet-syntax* +snippets snipMate.txt /*snippets* diff --git a/ftplugin/html_snip_helper.vim b/ftplugin/html_snip_helper.vim new file mode 100644 index 0000000..2e54570 --- /dev/null +++ b/ftplugin/html_snip_helper.vim @@ -0,0 +1,10 @@ +" Helper function for (x)html snippets +if exists('s:did_snip_helper') || &cp || !exists('loaded_snips') + finish +endif +let s:did_snip_helper = 1 + +" Automatically closes tag if in xhtml +fun! Close() + return stridx(&ft, 'xhtml') == -1 ? '' : ' /' +endf diff --git a/plugin/snipMate.vim b/plugin/snipMate.vim new file mode 100644 index 0000000..3efee2a --- /dev/null +++ b/plugin/snipMate.vim @@ -0,0 +1,247 @@ +" File: snipMate.vim +" Author: Michael Sanders +" Last Updated: July 13, 2009 +" Version: 0.83 +" Description: snipMate.vim implements some of TextMate's snippets features in +" Vim. A snippet is a piece of often-typed text that you can +" insert into your document using a trigger word followed by a "". +" +" For more help see snipMate.txt; you can do this by using: +" :helptags ~/.vim/doc +" :h snipMate.txt + +if exists('loaded_snips') || &cp || version < 700 + finish +endif +let loaded_snips = 1 +if !exists('snips_author') | let snips_author = 'Me' | endif + +au BufRead,BufNewFile *.snippets\= set ft=snippet +au FileType snippet setl noet fdm=indent + +let s:snippets = {} | let s:multi_snips = {} + +if !exists('snippets_dir') + let snippets_dir = substitute(globpath(&rtp, 'snippets/'), "\n", ',', 'g') +endif + +fun! MakeSnip(scope, trigger, content, ...) + let multisnip = a:0 && a:1 != '' + let var = multisnip ? 's:multi_snips' : 's:snippets' + if !has_key({var}, a:scope) | let {var}[a:scope] = {} | endif + if !has_key({var}[a:scope], a:trigger) + let {var}[a:scope][a:trigger] = multisnip ? [[a:1, a:content]] : a:content + elseif multisnip | let {var}[a:scope][a:trigger] += [[a:1, a:content]] + else + echom 'Warning in snipMate.vim: Snippet '.a:trigger.' is already defined.' + \ .' See :h multi_snip for help on snippets with multiple matches.' + endif +endf + +fun! ExtractSnips(dir, ft) + for path in split(globpath(a:dir, '*'), "\n") + if isdirectory(path) + let pathname = fnamemodify(path, ':t') + for snipFile in split(globpath(path, '*.snippet'), "\n") + call s:ProcessFile(snipFile, a:ft, pathname) + endfor + elseif fnamemodify(path, ':e') == 'snippet' + call s:ProcessFile(path, a:ft) + endif + endfor +endf + +" Processes a single-snippet file; optionally add the name of the parent +" directory for a snippet with multiple matches. +fun s:ProcessFile(file, ft, ...) + let keyword = fnamemodify(a:file, ':t:r') + if keyword == '' | return | endif + try + let text = join(readfile(a:file), "\n") + catch /E484/ + echom "Error in snipMate.vim: couldn't read file: ".a:file + endtry + return a:0 ? MakeSnip(a:ft, a:1, text, keyword) + \ : MakeSnip(a:ft, keyword, text) +endf + +fun! ExtractSnipsFile(file, ft) + if !filereadable(a:file) | return | endif + let text = readfile(a:file) + let inSnip = 0 + for line in text + ["\n"] + if inSnip && (line[0] == "\t" || line == '') + let content .= strpart(line, 1)."\n" + continue + elseif inSnip + call MakeSnip(a:ft, trigger, content[:-2], name) + let inSnip = 0 + endif + + if line[:6] == 'snippet' + let inSnip = 1 + let trigger = strpart(line, 8) + let name = '' + let space = stridx(trigger, ' ') + 1 + if space " Process multi snip + let name = strpart(trigger, space) + let trigger = strpart(trigger, 0, space - 1) + endif + let content = '' + endif + endfor +endf + +fun! ResetSnippets() + let s:snippets = {} | let s:multi_snips = {} | let g:did_ft = {} +endf + +let g:did_ft = {} +fun! GetSnippets(dir, filetypes) + for ft in split(a:filetypes, '\.') + if has_key(g:did_ft, ft) | continue | endif + call s:DefineSnips(a:dir, ft, ft) + if ft == 'objc' || ft == 'cpp' || ft == 'cs' + call s:DefineSnips(a:dir, 'c', ft) + elseif ft == 'xhtml' + call s:DefineSnips(a:dir, 'html', 'xhtml') + endif + let g:did_ft[ft] = 1 + endfor +endf + +" Define "aliasft" snippets for the filetype "realft". +fun s:DefineSnips(dir, aliasft, realft) + for path in split(globpath(a:dir, a:aliasft.'/')."\n". + \ globpath(a:dir, a:aliasft.'-*/'), "\n") + call ExtractSnips(path, a:realft) + endfor + for path in split(globpath(a:dir, a:aliasft.'.snippets')."\n". + \ globpath(a:dir, a:aliasft.'-*.snippets'), "\n") + call ExtractSnipsFile(path, a:realft) + endfor +endf + +fun! TriggerSnippet() + if exists('g:SuperTabMappingForward') + if g:SuperTabMappingForward == "" + let SuperTabKey = "\" + elseif g:SuperTabMappingBackward == "" + let SuperTabKey = "\" + endif + endif + + if pumvisible() " Update snippet if completion is used, or deal with supertab + if exists('SuperTabKey') + call feedkeys(SuperTabKey) | return '' + endif + call feedkeys("\a", 'n') " Close completion menu + call feedkeys("\") | return '' + endif + + if exists('g:snipPos') | return snipMate#jumpTabStop(0) | endif + + let word = matchstr(getline('.'), '\S\+\%'.col('.').'c') + for scope in [bufnr('%')] + split(&ft, '\.') + ['_'] + let [trigger, snippet] = s:GetSnippet(word, scope) + " If word is a trigger for a snippet, delete the trigger & expand + " the snippet. + if snippet != '' + let col = col('.') - len(trigger) + sil exe 's/\V'.escape(trigger, '/.').'\%#//' + return snipMate#expandSnip(snippet, col) + endif + endfor + + if exists('SuperTabKey') + call feedkeys(SuperTabKey) + return '' + endif + return "\" +endf + +fun! BackwardsSnippet() + if exists('g:snipPos') | return snipMate#jumpTabStop(1) | endif + + if exists('g:SuperTabMappingForward') + if g:SuperTabMappingBackward == "" + let SuperTabKey = "\" + elseif g:SuperTabMappingForward == "" + let SuperTabKey = "\" + endif + endif + if exists('SuperTabKey') + call feedkeys(SuperTabKey) + return '' + endif + return "\" +endf + +" Check if word under cursor is snippet trigger; if it isn't, try checking if +" the text after non-word characters is (e.g. check for "foo" in "bar.foo") +fun s:GetSnippet(word, scope) + let word = a:word | let snippet = '' + while snippet == '' + if exists('s:snippets["'.a:scope.'"]["'.escape(word, '\"').'"]') + let snippet = s:snippets[a:scope][word] + elseif exists('s:multi_snips["'.a:scope.'"]["'.escape(word, '\"').'"]') + let snippet = s:ChooseSnippet(a:scope, word) + if snippet == '' | break | endif + else + if match(word, '\W') == -1 | break | endif + let word = substitute(word, '.\{-}\W', '', '') + endif + endw + if word == '' && a:word != '.' && stridx(a:word, '.') != -1 + let [word, snippet] = s:GetSnippet('.', a:scope) + endif + return [word, snippet] +endf + +fun s:ChooseSnippet(scope, trigger) + let snippet = [] + let i = 1 + for snip in s:multi_snips[a:scope][a:trigger] + let snippet += [i.'. '.snip[0]] + let i += 1 + endfor + if i == 2 | return s:multi_snips[a:scope][a:trigger][0][1] | endif + let num = inputlist(snippet) - 1 + return num == -1 ? '' : s:multi_snips[a:scope][a:trigger][num][1] +endf + +fun! ShowAvailableSnips() + let line = getline('.') + let col = col('.') + let word = matchstr(getline('.'), '\S\+\%'.col.'c') + let words = [word] + if stridx(word, '.') + let words += split(word, '\.', 1) + endif + let matchlen = 0 + let matches = [] + for scope in [bufnr('%')] + split(&ft, '\.') + ['_'] + let triggers = has_key(s:snippets, scope) ? keys(s:snippets[scope]) : [] + if has_key(s:multi_snips, scope) + let triggers += keys(s:multi_snips[scope]) + endif + for trigger in triggers + for word in words + if word == '' + let matches += [trigger] " Show all matches if word is empty + elseif trigger =~ '^'.word + let matches += [trigger] + let len = len(word) + if len > matchlen | let matchlen = len | endif + endif + endfor + endfor + endfor + + " This is to avoid a bug with Vim when using complete(col - matchlen, matches) + " (Issue#46 on the Google Code snipMate issue tracker). + call setline(line('.'), substitute(line, repeat('.', matchlen).'\%'.col.'c', '', '')) + call complete(col, matches) + return '' +endf +" vim:noet:sw=4:ts=4:ft=vim diff --git a/snippets/_/lorem.snippet b/snippets/_/lorem.snippet index 85303ce..7e1929b 100644 --- a/snippets/_/lorem.snippet +++ b/snippets/_/lorem.snippet @@ -1,4 +1 @@ -Lorem ipsum dolor sit amet, consectetur magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation -ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate -velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in -culpa qui officia deserunt mollit anim id est laborum${1} +Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Vivamus vitae risus vitae lorem iaculis placerat. Aliquam sit amet felis. Etiam congue. Donec risus risus, pretium ac, tincidunt eu, tempor eu, quam. Morbi blandit mollis magna. Suspendisse eu tortor. Donec vitae felis nec ligula blandit rhoncus. Ut a pede ac neque mattis facilisis. Nulla nunc ipsum, sodales vitae, hendrerit non, imperdiet ac, ante. Morbi sit amet mi. Ut magna. Curabitur id est. Nulla velit. Sed consectetuer sodales justo. Aliquam dictum gravida libero. Sed eu turpis. Nunc id lorem. Aenean consequat tempor mi. Phasellus in neque. Nunc fermentum convallis ligula. diff --git a/snippets/css/class.snippet b/snippets/css/class.snippet new file mode 100644 index 0000000..8c996cb --- /dev/null +++ b/snippets/css/class.snippet @@ -0,0 +1,3 @@ +.${1:class} { + ${2} +} diff --git a/snippets/eruby-rails/jsit.snippet b/snippets/eruby-rails/jsit.snippet index 187e9ab..e14c3e7 100644 --- a/snippets/eruby-rails/jsit.snippet +++ b/snippets/eruby-rails/jsit.snippet @@ -1 +1 @@ -<%= javascript_include_tag "${1}" %> +<%= javascript_include_tag ${1::all}, :cache => ${2:true} %> diff --git a/snippets/eruby-rails/rp.snippet b/snippets/eruby-rails/rp.snippet index 706a4cb..8e38dd1 100644 --- a/snippets/eruby-rails/rp.snippet +++ b/snippets/eruby-rails/rp.snippet @@ -1 +1 @@ -<%= render :partial => "${1:file}"${2} %> +<%= render "${1:file}"${2} %> diff --git a/snippets/eruby-rails/sslt.snippet b/snippets/eruby-rails/sslt.snippet index 1fd0f68..87fcdfe 100644 --- a/snippets/eruby-rails/sslt.snippet +++ b/snippets/eruby-rails/sslt.snippet @@ -1 +1 @@ -<%= stylesheet_link_tag "${1}" %> +<%= stylesheet_link_tag ${1::all}, :cache => ${2:true} %> diff --git a/snippets/grails/bt.snippet b/snippets/grails/bt.snippet new file mode 100644 index 0000000..b10872b --- /dev/null +++ b/snippets/grails/bt.snippet @@ -0,0 +1 @@ +static belongsTo = [${1:varName:} ${2:DomainName}] diff --git a/snippets/grails/crit.snippet b/snippets/grails/crit.snippet new file mode 100644 index 0000000..3143c61 --- /dev/null +++ b/snippets/grails/crit.snippet @@ -0,0 +1,3 @@ +def ${1:varName} = ${2:domainName}.withCriteria { + ${3} +} diff --git a/snippets/grails/fall.snippet b/snippets/grails/fall.snippet new file mode 100644 index 0000000..50f8228 --- /dev/null +++ b/snippets/grails/fall.snippet @@ -0,0 +1 @@ +${1:domainName}.findAll${2:Attribute}(${3:value})${4} diff --git a/snippets/grails/find.snippet b/snippets/grails/find.snippet new file mode 100644 index 0000000..3503aba --- /dev/null +++ b/snippets/grails/find.snippet @@ -0,0 +1 @@ +${1:domainName}.findBy${2:Attribute}(${3:value})${4} diff --git a/snippets/grails/hm.snippet b/snippets/grails/hm.snippet new file mode 100644 index 0000000..b0b3c17 --- /dev/null +++ b/snippets/grails/hm.snippet @@ -0,0 +1 @@ +static hasMany = [${1:listName}: ${2:DomainName}] diff --git a/snippets/grails/ho.snippet b/snippets/grails/ho.snippet new file mode 100644 index 0000000..2eab808 --- /dev/null +++ b/snippets/grails/ho.snippet @@ -0,0 +1 @@ +static hasOne = [${1:attrName:} ${2:DomainName}] diff --git a/snippets/grails/mconfig.snippet b/snippets/grails/mconfig.snippet new file mode 100644 index 0000000..1bcd074 --- /dev/null +++ b/snippets/grails/mconfig.snippet @@ -0,0 +1,3 @@ +mockConfig """ + ${1} +""" diff --git a/snippets/grails/mdomain.snippet b/snippets/grails/mdomain.snippet new file mode 100644 index 0000000..4eadd74 --- /dev/null +++ b/snippets/grails/mdomain.snippet @@ -0,0 +1 @@ +mockDomain(${1:DomainClass},[${2:objList}])${3} diff --git a/snippets/grails/mp.snippet b/snippets/grails/mp.snippet new file mode 100644 index 0000000..0944f9d --- /dev/null +++ b/snippets/grails/mp.snippet @@ -0,0 +1 @@ +mockParams.${1:varName} = '${2:value}'${3} diff --git a/snippets/grails/mserv.snippet b/snippets/grails/mserv.snippet new file mode 100644 index 0000000..01bfd1c --- /dev/null +++ b/snippets/grails/mserv.snippet @@ -0,0 +1,4 @@ +def service = mockForm(${1:serviceName}) +service.demand.${2:methodName}(1..${3:1}) { ${4:params ->} + ${5} +} diff --git a/snippets/grails/red.snippet b/snippets/grails/red.snippet new file mode 100644 index 0000000..3b43e4d --- /dev/null +++ b/snippets/grails/red.snippet @@ -0,0 +1 @@ +redirect controller:${1:controllerName}, action:${2:actionName} params:[${3:params}] diff --git a/snippets/grails/render.snippet b/snippets/grails/render.snippet new file mode 100644 index 0000000..4777483 --- /dev/null +++ b/snippets/grails/render.snippet @@ -0,0 +1 @@ +render view:"${1:viewName}", model:[${2:modelMap}] diff --git a/snippets/grails/tag.snippet b/snippets/grails/tag.snippet new file mode 100644 index 0000000..cd65f8d --- /dev/null +++ b/snippets/grails/tag.snippet @@ -0,0 +1,4 @@ +def ${1:tagName} = { attr, body -> + out << ${2} + +} diff --git a/snippets/grails/test.snippet b/snippets/grails/test.snippet new file mode 100644 index 0000000..718bb96 --- /dev/null +++ b/snippets/grails/test.snippet @@ -0,0 +1,3 @@ +public void test${1:Name}() { + ${2} +} diff --git a/snippets/groovy/class.snippet b/snippets/groovy/class.snippet new file mode 100644 index 0000000..a412000 --- /dev/null +++ b/snippets/groovy/class.snippet @@ -0,0 +1,3 @@ +class ${1:className} { + ${2} +} diff --git a/snippets/groovy/cls.snippet b/snippets/groovy/cls.snippet new file mode 100644 index 0000000..aa15aea --- /dev/null +++ b/snippets/groovy/cls.snippet @@ -0,0 +1,3 @@ +def ${1:closureName} = { ${2: param ->} + ${3} +} diff --git a/snippets/groovy/each.snippet b/snippets/groovy/each.snippet new file mode 100644 index 0000000..3a06c5a --- /dev/null +++ b/snippets/groovy/each.snippet @@ -0,0 +1,3 @@ +${1:listName}.each { ${2: varName ->} + ${3} +} diff --git a/snippets/groovy/if.snippet b/snippets/groovy/if.snippet new file mode 100644 index 0000000..3d8a1d1 --- /dev/null +++ b/snippets/groovy/if.snippet @@ -0,0 +1,3 @@ +if( ${1:exp} ) { + ${2} +} diff --git a/snippets/gsp/geach.snippet b/snippets/gsp/geach.snippet new file mode 100644 index 0000000..a34d63d --- /dev/null +++ b/snippets/gsp/geach.snippet @@ -0,0 +1,3 @@ + + ${3} + diff --git a/snippets/gsp/gform.snippet b/snippets/gsp/gform.snippet new file mode 100644 index 0000000..cbb8e51 --- /dev/null +++ b/snippets/gsp/gform.snippet @@ -0,0 +1,3 @@ + + ${3} + diff --git a/snippets/gsp/gherr.snippet b/snippets/gsp/gherr.snippet new file mode 100644 index 0000000..1b5f6d4 --- /dev/null +++ b/snippets/gsp/gherr.snippet @@ -0,0 +1,4 @@ + + ${2} + + diff --git a/snippets/gsp/gif.snippet b/snippets/gsp/gif.snippet new file mode 100644 index 0000000..1eff6d1 --- /dev/null +++ b/snippets/gsp/gif.snippet @@ -0,0 +1,3 @@ + + ${2} + diff --git a/snippets/gsp/ginput.snippet b/snippets/gsp/ginput.snippet new file mode 100644 index 0000000..bd8af93 --- /dev/null +++ b/snippets/gsp/ginput.snippet @@ -0,0 +1 @@ + diff --git a/snippets/gsp/gjs.snippet b/snippets/gsp/gjs.snippet new file mode 100644 index 0000000..be8f68f --- /dev/null +++ b/snippets/gsp/gjs.snippet @@ -0,0 +1 @@ + diff --git a/snippets/gsp/glink.snippet b/snippets/gsp/glink.snippet new file mode 100755 index 0000000..ad660ea --- /dev/null +++ b/snippets/gsp/glink.snippet @@ -0,0 +1,3 @@ + + ${4} + diff --git a/snippets/gsp/gsel.snippet b/snippets/gsp/gsel.snippet new file mode 100644 index 0000000..2b40ab0 --- /dev/null +++ b/snippets/gsp/gsel.snippet @@ -0,0 +1 @@ +${4} diff --git a/snippets/gsp/gsubmit.snippet b/snippets/gsp/gsubmit.snippet new file mode 100644 index 0000000..9d33cff --- /dev/null +++ b/snippets/gsp/gsubmit.snippet @@ -0,0 +1 @@ +${5} diff --git a/snippets/gsp/gtemplate.snippet b/snippets/gsp/gtemplate.snippet new file mode 100644 index 0000000..ab78755 --- /dev/null +++ b/snippets/gsp/gtemplate.snippet @@ -0,0 +1 @@ +${3} diff --git a/snippets/gsp/skel/layout.snippet b/snippets/gsp/skel/layout.snippet new file mode 100644 index 0000000..61428d3 --- /dev/null +++ b/snippets/gsp/skel/layout.snippet @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/snippets/javascript/forin.snippet b/snippets/javascript/forin.snippet new file mode 100644 index 0000000..cfd36e1 --- /dev/null +++ b/snippets/javascript/forin.snippet @@ -0,0 +1,3 @@ +for (var ${1:arg} in ${2:obj}) { + ${3} +} diff --git a/snippets/javascript/getter.snippet b/snippets/javascript/getter.snippet new file mode 100644 index 0000000..4abed38 --- /dev/null +++ b/snippets/javascript/getter.snippet @@ -0,0 +1,3 @@ +${1:class_name}.prototype.__defineGetter__("${3:property}", function () { + ${4:return} ${5:// body}; +}); diff --git a/snippets/javascript/if.snippet b/snippets/javascript/if.snippet index d81ac04..f4aa67a 100644 --- a/snippets/javascript/if.snippet +++ b/snippets/javascript/if.snippet @@ -1,3 +1,3 @@ -if (${1:true}) { - ${2} -}; +if (${1:true}) { + ${2} +} diff --git a/snippets/javascript/ife.snippet b/snippets/javascript/ife.snippet index 7adadbc..5900b84 100644 --- a/snippets/javascript/ife.snippet +++ b/snippets/javascript/ife.snippet @@ -1,4 +1,5 @@ -if (${1:true}) { +if(${1:true}) { ${2} } else { + ${3} } diff --git a/snippets/javascript/iff.snippet b/snippets/javascript/iff.snippet index f4aa67a..a175c0d 100644 --- a/snippets/javascript/iff.snippet +++ b/snippets/javascript/iff.snippet @@ -1,3 +1,3 @@ if (${1:true}) { ${2} -} +}; diff --git a/snippets/javascript/setter.snippet b/snippets/javascript/setter.snippet new file mode 100644 index 0000000..29d6da5 --- /dev/null +++ b/snippets/javascript/setter.snippet @@ -0,0 +1,3 @@ +${1:class_name}.prototype.__defineSetter__("${3:property}", function (${4:val}) { + ${5:// body} +}); diff --git a/snippets/javascript/siaf.snippet b/snippets/javascript/siaf.snippet new file mode 100644 index 0000000..eab0896 --- /dev/null +++ b/snippets/javascript/siaf.snippet @@ -0,0 +1,3 @@ +(function() { + ${1} +})(); diff --git a/snippets/javascript/swi.snippet b/snippets/javascript/swi.snippet new file mode 100644 index 0000000..ebd5f76 --- /dev/null +++ b/snippets/javascript/swi.snippet @@ -0,0 +1,8 @@ +switch (${1:expression}) { + case ${2:option}: + ${3} + break; + default: + ${4} + break; +} diff --git a/snippets/javascript/try.snippet b/snippets/javascript/try.snippet new file mode 100644 index 0000000..ed78e54 --- /dev/null +++ b/snippets/javascript/try.snippet @@ -0,0 +1,6 @@ +try { + ${1:// code...} +} catch (e) { + ${2:// code...} +} + diff --git a/snippets/php/req1.snippet b/snippets/php/reqo.snippet similarity index 100% rename from snippets/php/req1.snippet rename to snippets/php/reqo.snippet diff --git a/snippets/php/req.snippet b/snippets/php/requ.snippet similarity index 100% rename from snippets/php/req.snippet rename to snippets/php/requ.snippet diff --git a/snippets/python/class.snippet b/snippets/python/class.snippet index d9e2b8e..736b36c 100644 --- a/snippets/python/class.snippet +++ b/snippets/python/class.snippet @@ -1,2 +1,3 @@ -class ${1:``Snippet_PythonClassNameFromFilename()``}(${2:data}): -${3} +class ${1:`Snippet_PythonClassNameFromFilename()`}(${2:data}): + ${3} + diff --git a/snippets/ruby-rails/art.snippet b/snippets/ruby-rails/art.snippet index a5a7d34..62e130e 100644 --- a/snippets/ruby-rails/art.snippet +++ b/snippets/ruby-rails/art.snippet @@ -1 +1 @@ -assert_redirected_to ${1::action => "${2:index}"} +assert_redirected_to ${1:action} diff --git a/snippets/ruby-rails/artnp.snippet b/snippets/ruby-rails/artnp.snippet index 2c9bfef..f260710 100644 --- a/snippets/ruby-rails/artnp.snippet +++ b/snippets/ruby-rails/artnp.snippet @@ -1 +1 @@ -assert_redirected_to <+<+parent+>_<+child+>_path(<+@<+parent+>+>, <+@<+child+>+>)+> +assert_redirected_to ${2:${12:parent}_${13:child}_path(${14:@}${15:${12}}, ${16:@}${17:${13}})} diff --git a/snippets/ruby-rails/artnpp.snippet b/snippets/ruby-rails/artnpp.snippet index becd79b..fd614d1 100644 --- a/snippets/ruby-rails/artnpp.snippet +++ b/snippets/ruby-rails/artnpp.snippet @@ -1 +1 @@ -assert_redirected_to <+<+parent+>_<+child+>_path(<+@<+parent+>+>)+> +assert_redirected_to ${10:${2:parent}_${3:child}_path(${4:@}${5:${2}})} diff --git a/snippets/ruby-rails/artp.snippet b/snippets/ruby-rails/artp.snippet index 55b9204..918634c 100644 --- a/snippets/ruby-rails/artp.snippet +++ b/snippets/ruby-rails/artp.snippet @@ -1 +1 @@ -assert_redirected_to <+<+model+>_path(<+@<+model+>+>)+> +assert_redirected_to ${2:${12:model}_path(${13:@}${14:${12}})} diff --git a/snippets/ruby-rails/artpp.snippet b/snippets/ruby-rails/artpp.snippet index 1d1d203..5e6bfa7 100644 --- a/snippets/ruby-rails/artpp.snippet +++ b/snippets/ruby-rails/artpp.snippet @@ -1 +1 @@ -assert_redirected_to <+<+model+>s_path+> +assert_redirected_to ${10:${2:model}s_path} diff --git a/snippets/ruby-rails/asrj.snippet b/snippets/ruby-rails/asrj.snippet index 6ee13f2..b584800 100644 --- a/snippets/ruby-rails/asrj.snippet +++ b/snippets/ruby-rails/asrj.snippet @@ -1 +1 @@ -assert_rjs :<+replace+>, <+"<+dom id+>"+> +assert_rjs :${1:replace}, ${2:"${3:dom id}"} diff --git a/snippets/ruby-rails/ass.snippet b/snippets/ruby-rails/ass.snippet index 4cc696f..a21e380 100644 --- a/snippets/ruby-rails/ass.snippet +++ b/snippets/ruby-rails/ass.snippet @@ -1 +1,4 @@ -assert_select '<+path+>'<+, :<+text+> => <+'<+inner_html+>'+>+> <+do<++>+> +assert_select '${1:path}'${2:, :${3:text} => ${4:'${5:inner_html}'}}${6: do + $0 +end} + diff --git a/snippets/ruby-rails/habtm.snippet b/snippets/ruby-rails/habtm.snippet index 1b27396..2403aeb 100644 --- a/snippets/ruby-rails/habtm.snippet +++ b/snippets/ruby-rails/habtm.snippet @@ -1 +1 @@ -has_and_belongs_to_many :${1:object}, :join_table => "${2:table_name}", :foreign_key => "${3}_id"${4} +has_and_belongs_to_many :${1:object} diff --git a/snippets/ruby-rails/hmd.snippet b/snippets/ruby-rails/hmd.snippet index 6aadd73..42472d8 100644 --- a/snippets/ruby-rails/hmd.snippet +++ b/snippets/ruby-rails/hmd.snippet @@ -1 +1 @@ -has_many :<+object+>s<+, :class_name => "<+object+>", :foreign_key => "<+reference+>_id"+>, :dependent => :destroy<++> +has_many :${1:object}s${2:, :class_name => "${1}", :foreign_key => "${4:reference}_id"} diff --git a/snippets/ruby-rails/mct.snippet b/snippets/ruby-rails/mct.snippet index 8dbe1ea..3b3e6ca 100644 --- a/snippets/ruby-rails/mct.snippet +++ b/snippets/ruby-rails/mct.snippet @@ -1,3 +1,3 @@ -create_table :${1:table_name} do |t| - t.column :${2:name}, :${3:type} +create_table :${1} do |t| + t.${3:integer} :${2} end diff --git a/snippets/ruby-rails/nc.snippet b/snippets/ruby-rails/nc.snippet index cfc42ca..9f93b39 100644 --- a/snippets/ruby-rails/nc.snippet +++ b/snippets/ruby-rails/nc.snippet @@ -1 +1 @@ -named_scope :<+name+><+, :joins => :<+table+>+>, :conditions => <+['<+<+field+> = ?+>', <+true+>]+> +named_scope :${1:name}${2:, :joins => :${3:table}}, :conditions => ${4:['${5:${6:field} = ?}', ${7:true}]} diff --git a/snippets/ruby-rails/ncl.snippet b/snippets/ruby-rails/ncl.snippet index c420ef2..072882d 100644 --- a/snippets/ruby-rails/ncl.snippet +++ b/snippets/ruby-rails/ncl.snippet @@ -1 +1 @@ -named_scope :<+name+>, lambda { |<+param+>| { :conditions => <+['<+<+field+> = ?+>', <+param+>]+> } } +named_scope :${1:name}, lambda { |${2:param}| { :conditions => ${3:['${4:${5:field} = ?}', ${6:$2}]} } } diff --git a/snippets/ruby-rails/ri.snippet b/snippets/ruby-rails/ri.snippet index 17a0404..c002e1a 100644 --- a/snippets/ruby-rails/ri.snippet +++ b/snippets/ruby-rails/ri.snippet @@ -1 +1 @@ -render :inline => "<+<%= 'hello' %>+>" +render :inline => "${1:<%= 'hello' %>}" diff --git a/snippets/ruby-rails/rpc.snippet b/snippets/ruby-rails/rpc.snippet index 570644b..393b682 100644 --- a/snippets/ruby-rails/rpc.snippet +++ b/snippets/ruby-rails/rpc.snippet @@ -1 +1 @@ -render :partial => "<+item+>", :collection => <+@<+item+>s+> +render :partial => "${1:item}", :collection => ${2:@$1s} diff --git a/snippets/ruby-rails/rpl.snippet b/snippets/ruby-rails/rpl.snippet index 6981fbc..bedc6e9 100644 --- a/snippets/ruby-rails/rpl.snippet +++ b/snippets/ruby-rails/rpl.snippet @@ -1 +1 @@ -render :partial => "<+item+>", :locals => { :<+item+> => <+@<+item+>+><++> } +render :partial => "${1:item}", :locals => { :${2:$1} => ${3:@$1}$0 } diff --git a/snippets/ruby-rails/rpo.snippet b/snippets/ruby-rails/rpo.snippet index bab9da9..ccc1c2d 100644 --- a/snippets/ruby-rails/rpo.snippet +++ b/snippets/ruby-rails/rpo.snippet @@ -1 +1 @@ -render :partial => "<+item+>", :object => <+@<+item+>+> +render :partial => "${1:item}", :object => ${2:@$1} diff --git a/snippets/ruby-rails/rt.snippet b/snippets/ruby-rails/rt.snippet index c464879..42bee39 100644 --- a/snippets/ruby-rails/rt.snippet +++ b/snippets/ruby-rails/rt.snippet @@ -1 +1 @@ -render :text => "${1:text to render}" +render :text => "${1:text to render...}", :layout => "${2:layoutname}" diff --git a/snippets/ruby-rails/tcb.snippet b/snippets/ruby-rails/tcb.snippet index 021740d..f703d9d 100644 --- a/snippets/ruby-rails/tcb.snippet +++ b/snippets/ruby-rails/tcb.snippet @@ -1,2 +1 @@ -t.boolean :${1:title} -${2} +t.boolean :${1:truthly} diff --git a/snippets/ruby-rails/tcbi.snippet b/snippets/ruby-rails/tcbi.snippet index 3e6d3c9..0d35acc 100644 --- a/snippets/ruby-rails/tcbi.snippet +++ b/snippets/ruby-rails/tcbi.snippet @@ -1,2 +1 @@ -t.binary :<+title+><+, :limit => <+2+>.megabytes+> -<++> +t.binary :${1}, :limit => ${2:2.megabytes} diff --git a/snippets/ruby-rails/tcda.snippet b/snippets/ruby-rails/tcda.snippet index b716e8b..a82cfbc 100644 --- a/snippets/ruby-rails/tcda.snippet +++ b/snippets/ruby-rails/tcda.snippet @@ -1,2 +1 @@ -t.date :${1:title} -${2} +t.date :${1:date} diff --git a/snippets/ruby-rails/tcdt.snippet b/snippets/ruby-rails/tcdt.snippet index d060532..b5c26b2 100644 --- a/snippets/ruby-rails/tcdt.snippet +++ b/snippets/ruby-rails/tcdt.snippet @@ -1,2 +1 @@ t.datetime :${1:title} -${2} diff --git a/snippets/ruby-rails/tcf.snippet b/snippets/ruby-rails/tcf.snippet index f09f790..9658853 100644 --- a/snippets/ruby-rails/tcf.snippet +++ b/snippets/ruby-rails/tcf.snippet @@ -1,2 +1 @@ -t.float :${1:title} -${2} +t.float :${1:value} diff --git a/snippets/ruby-rails/tch.snippet b/snippets/ruby-rails/tch.snippet index bcce727..bc273d0 100644 --- a/snippets/ruby-rails/tch.snippet +++ b/snippets/ruby-rails/tch.snippet @@ -1,2 +1,3 @@ -t.change :<+name+><+, :<+string+><+, :<+limit+> => <+80+>+>+> -<++> +t.change :${1:name}${2:, :${3:string}${4:, :${5:limit} => ${6:80}}} +t.$0 + diff --git a/snippets/ruby-rails/tci.snippet b/snippets/ruby-rails/tci.snippet index 7cb011c..6e35d94 100644 --- a/snippets/ruby-rails/tci.snippet +++ b/snippets/ruby-rails/tci.snippet @@ -1,2 +1 @@ -t.integer :${1:title} -${2} +t.integer :${1:id} diff --git a/snippets/ruby-rails/tcl.snippet b/snippets/ruby-rails/tcl.snippet index ffa359f..c5d8c93 100644 --- a/snippets/ruby-rails/tcl.snippet +++ b/snippets/ruby-rails/tcl.snippet @@ -1,2 +1 @@ t.integer :lock_version, :null => false, :default => 0 -${1} diff --git a/snippets/ruby-rails/tcr.snippet b/snippets/ruby-rails/tcr.snippet index 2b421dd..db84703 100644 --- a/snippets/ruby-rails/tcr.snippet +++ b/snippets/ruby-rails/tcr.snippet @@ -1,2 +1,3 @@ -t.references :<+taggable+><+, :polymorphic => <+{ :default => '<+Photo+>' }+>+> -<++> +t.references :${1:taggable}${2:, :polymorphic => ${3:{ :default => '${4:Photo}' \}}} +t.$0 + diff --git a/snippets/ruby-rails/tcs.snippet b/snippets/ruby-rails/tcs.snippet index a7b8473..d8cf15f 100644 --- a/snippets/ruby-rails/tcs.snippet +++ b/snippets/ruby-rails/tcs.snippet @@ -1,2 +1 @@ t.string :${1:title} -${2} diff --git a/snippets/ruby-rails/tct.snippet b/snippets/ruby-rails/tct.snippet index f28518f..3888c64 100644 --- a/snippets/ruby-rails/tct.snippet +++ b/snippets/ruby-rails/tct.snippet @@ -1,2 +1 @@ -t.text :${1:title} -${2} +t.text :${1:body} diff --git a/snippets/ruby-rails/tcti.snippet b/snippets/ruby-rails/tcti.snippet index 0006c81..b9b6998 100644 --- a/snippets/ruby-rails/tcti.snippet +++ b/snippets/ruby-rails/tcti.snippet @@ -1,2 +1 @@ t.time :${1:title} -${2} diff --git a/snippets/ruby-rails/tcts.snippet b/snippets/ruby-rails/tcts.snippet index e46e844..092c752 100644 --- a/snippets/ruby-rails/tcts.snippet +++ b/snippets/ruby-rails/tcts.snippet @@ -1,2 +1 @@ t.timestamp :${1:title} -${2} diff --git a/snippets/ruby-rails/tctss.snippet b/snippets/ruby-rails/tctss.snippet index f009ee6..90e6bc3 100644 --- a/snippets/ruby-rails/tctss.snippet +++ b/snippets/ruby-rails/tctss.snippet @@ -1,2 +1 @@ t.timestamps -${1} diff --git a/snippets/ruby-rails/tre.snippet b/snippets/ruby-rails/tre.snippet index 8f70788..b21638d 100644 --- a/snippets/ruby-rails/tre.snippet +++ b/snippets/ruby-rails/tre.snippet @@ -1,2 +1,3 @@ -t.rename :<+old_column_name+>, :<+new_column_name+> -<++> +t.rename :${1:old_column_name}, :${2:new_column_name} +t.$0 + diff --git a/snippets/ruby-rails/vi.snippet b/snippets/ruby-rails/vi.snippet index 8ba16d2..d82f8e2 100644 --- a/snippets/ruby-rails/vi.snippet +++ b/snippets/ruby-rails/vi.snippet @@ -1 +1 @@ -validates_inclusion_of :${1:attribute}, :in => %w(${2: mov avi }) +validates_inclusion_of :${1:attribute}, :in => ${2} diff --git a/snippets/ruby-rspec/bef.snippet b/snippets/ruby-rspec/bef.snippet index f96608c..67bd20d 100644 --- a/snippets/ruby-rspec/bef.snippet +++ b/snippets/ruby-rspec/bef.snippet @@ -1,3 +1,3 @@ -before(${1::each}) do - ${2} +before(:each) do + ${1} end diff --git a/snippets/ruby-rspec/moc.snippet b/snippets/ruby-rspec/moc.snippet index 4ff954f..33fc58d 100644 --- a/snippets/ruby-rspec/moc.snippet +++ b/snippets/ruby-rspec/moc.snippet @@ -1,2 +1 @@ -${1:var} = mock("${2:mock_name}"${3:, :null_object => true}) -${4} +mock("${2:mock_name}"${3:, :null_object => true}) diff --git a/snippets/ruby-rspec/sh.snippet b/snippets/ruby-rspec/sh.snippet index 67530e9..e30f429 100644 --- a/snippets/ruby-rspec/sh.snippet +++ b/snippets/ruby-rspec/sh.snippet @@ -1,2 +1 @@ ${1:target}.should == ${2:value} -${3} diff --git a/snippets/ruby-rspec/shb.snippet b/snippets/ruby-rspec/shb.snippet index b909d9c..6a8df35 100644 --- a/snippets/ruby-rspec/shb.snippet +++ b/snippets/ruby-rspec/shb.snippet @@ -1,2 +1 @@ ${1:target}.should be(${2:result}) -${3} diff --git a/snippets/ruby-rspec/shbc.snippet b/snippets/ruby-rspec/shbc.snippet index 9080a3c..3f9e87d 100644 --- a/snippets/ruby-rspec/shbc.snippet +++ b/snippets/ruby-rspec/shbc.snippet @@ -1,2 +1 @@ ${1:target}.should be_close(${2:result}, ${3:tolerance}) -${4} diff --git a/snippets/ruby-rspec/shbio.snippet b/snippets/ruby-rspec/shbio.snippet index 98a7389..d3961d7 100644 --- a/snippets/ruby-rspec/shbio.snippet +++ b/snippets/ruby-rspec/shbio.snippet @@ -1,2 +1 @@ ${1:target}.should be_instance_of(${2:class}) -${3} diff --git a/snippets/ruby-rspec/shbko.snippet b/snippets/ruby-rspec/shbko.snippet index 74bf852..14d4af8 100644 --- a/snippets/ruby-rspec/shbko.snippet +++ b/snippets/ruby-rspec/shbko.snippet @@ -1,2 +1 @@ ${1:target}.should be_a_kind_of(${2:class}) -${3} diff --git a/snippets/ruby-rspec/shbr.snippet b/snippets/ruby-rspec/shbr.snippet index 887ef80..2e68a41 100644 --- a/snippets/ruby-rspec/shbr.snippet +++ b/snippets/ruby-rspec/shbr.snippet @@ -1,2 +1 @@ response.should be_redirect -${1} diff --git a/snippets/ruby-rspec/shbs.snippet b/snippets/ruby-rspec/shbs.snippet index 602074b..642bd80 100644 --- a/snippets/ruby-rspec/shbs.snippet +++ b/snippets/ruby-rspec/shbs.snippet @@ -1,2 +1 @@ response.should be_success -${1} diff --git a/snippets/ruby-rspec/shdm.snippet b/snippets/ruby-rspec/shdm.snippet index e82d82e..3a6e732 100644 --- a/snippets/ruby-rspec/shdm.snippet +++ b/snippets/ruby-rspec/shdm.snippet @@ -1,2 +1 @@ ${1:target}.should match(/${2:regexp}/) -${3} diff --git a/snippets/ruby-rspec/she.snippet b/snippets/ruby-rspec/she.snippet index f896a26..b98365d 100644 --- a/snippets/ruby-rspec/she.snippet +++ b/snippets/ruby-rspec/she.snippet @@ -1,2 +1 @@ ${1:target}.should eql(${2:value}) -${3} diff --git a/snippets/ruby-rspec/sheq.snippet b/snippets/ruby-rspec/sheq.snippet index e3c389e..5b71ef7 100644 --- a/snippets/ruby-rspec/sheq.snippet +++ b/snippets/ruby-rspec/sheq.snippet @@ -1,2 +1 @@ ${1:target}.should equal(${2:value}) -${3} diff --git a/snippets/ruby-rspec/shh.snippet b/snippets/ruby-rspec/shh.snippet index 93189cb..1e12932 100644 --- a/snippets/ruby-rspec/shh.snippet +++ b/snippets/ruby-rspec/shh.snippet @@ -1,2 +1 @@ ${1:target}.should have(${2:num}).${3:things} -${4} diff --git a/snippets/ruby-rspec/shhal.snippet b/snippets/ruby-rspec/shhal.snippet index dabe237..bd7285e 100644 --- a/snippets/ruby-rspec/shhal.snippet +++ b/snippets/ruby-rspec/shhal.snippet @@ -1,2 +1 @@ ${1:target}.should have_at_least(${2:num}).${3:things} -${4} diff --git a/snippets/ruby-rspec/shham.snippet b/snippets/ruby-rspec/shham.snippet index 7072add..32d8908 100644 --- a/snippets/ruby-rspec/shham.snippet +++ b/snippets/ruby-rspec/shham.snippet @@ -1,2 +1 @@ ${1:target}.should have_at_most(${2:num}).${3:things} -${4} diff --git a/snippets/ruby-rspec/shhr.snippet b/snippets/ruby-rspec/shhr.snippet index b8a8997..ae770ab 100644 --- a/snippets/ruby-rspec/shhr.snippet +++ b/snippets/ruby-rspec/shhr.snippet @@ -1,2 +1 @@ ${1:target}.should have(${2:n}).records -${3} diff --git a/snippets/ruby-rspec/shn.snippet b/snippets/ruby-rspec/shn.snippet index b19cbb6..a2d9321 100644 --- a/snippets/ruby-rspec/shn.snippet +++ b/snippets/ruby-rspec/shn.snippet @@ -1,2 +1 @@ ${1:target}.should_not == ${2:value} -${3} diff --git a/snippets/ruby-rspec/shnb.snippet b/snippets/ruby-rspec/shnb.snippet index a34d62e..5ce654e 100644 --- a/snippets/ruby-rspec/shnb.snippet +++ b/snippets/ruby-rspec/shnb.snippet @@ -1,2 +1 @@ ${1:target}.should_not be(${2:result}) -${3} diff --git a/snippets/ruby-rspec/shnbc.snippet b/snippets/ruby-rspec/shnbc.snippet index 55ac6d3..2f25522 100644 --- a/snippets/ruby-rspec/shnbc.snippet +++ b/snippets/ruby-rspec/shnbc.snippet @@ -1,2 +1 @@ ${1:target}.should_not be_close(${2:result}, ${3:tolerance}) -${4} diff --git a/snippets/ruby-rspec/shnbio.snippet b/snippets/ruby-rspec/shnbio.snippet index b6f1526..27b63aa 100644 --- a/snippets/ruby-rspec/shnbio.snippet +++ b/snippets/ruby-rspec/shnbio.snippet @@ -1,2 +1 @@ ${1:target}.should_not be_instance_of(${2:klass}) -${3} diff --git a/snippets/ruby-rspec/shnbko.snippet b/snippets/ruby-rspec/shnbko.snippet index 0b0cfc7..b8429f4 100644 --- a/snippets/ruby-rspec/shnbko.snippet +++ b/snippets/ruby-rspec/shnbko.snippet @@ -1,2 +1 @@ ${1:target}.should_not be_a_kind_of(${2:klass}) -${3} diff --git a/snippets/ruby-rspec/shnbr.snippet b/snippets/ruby-rspec/shnbr.snippet index 25519b0..445005c 100644 --- a/snippets/ruby-rspec/shnbr.snippet +++ b/snippets/ruby-rspec/shnbr.snippet @@ -1,2 +1 @@ response.should_not be_redirect -${1} diff --git a/snippets/ruby-rspec/shnbs.snippet b/snippets/ruby-rspec/shnbs.snippet index 7d35ab2..7185ef6 100644 --- a/snippets/ruby-rspec/shnbs.snippet +++ b/snippets/ruby-rspec/shnbs.snippet @@ -1,2 +1 @@ response.should_not be_success -${1} diff --git a/snippets/ruby-rspec/shne.snippet b/snippets/ruby-rspec/shne.snippet index 68a7451..8f0540c 100644 --- a/snippets/ruby-rspec/shne.snippet +++ b/snippets/ruby-rspec/shne.snippet @@ -1,2 +1 @@ ${1:target}.should_not eql(${2:value}) -${3} diff --git a/snippets/ruby-rspec/shneq.snippet b/snippets/ruby-rspec/shneq.snippet index da4f59b..393d127 100644 --- a/snippets/ruby-rspec/shneq.snippet +++ b/snippets/ruby-rspec/shneq.snippet @@ -1,2 +1 @@ - ${1:target}.should_not equal(${2:value}) - ${3} +${1:target}.should_not equal(${2:value}) diff --git a/snippets/ruby-rspec/shnm.snippet b/snippets/ruby-rspec/shnm.snippet index ee7b604..e32d0a5 100644 --- a/snippets/ruby-rspec/shnm.snippet +++ b/snippets/ruby-rspec/shnm.snippet @@ -1,2 +1 @@ ${1:target}.should_not match(/${2:regexp}/) -${3} diff --git a/snippets/ruby-rspec/shnr.snippet b/snippets/ruby-rspec/shnr.snippet index 98c0fc0..1581d3e 100644 --- a/snippets/ruby-rspec/shnr.snippet +++ b/snippets/ruby-rspec/shnr.snippet @@ -1,2 +1 @@ ${1:mock}.should_not_receive(:${2:message})${3} -${4} diff --git a/snippets/ruby-rspec/shnre.snippet b/snippets/ruby-rspec/shnre.snippet index fbf9604..b5f25ae 100644 --- a/snippets/ruby-rspec/shnre.snippet +++ b/snippets/ruby-rspec/shnre.snippet @@ -1,2 +1 @@ ${1:target}.should_not raise_error(${2:error}) -${3} diff --git a/snippets/ruby-rspec/shnredt.snippet b/snippets/ruby-rspec/shnredt.snippet index 2afb69c..a82a66c 100644 --- a/snippets/ruby-rspec/shnredt.snippet +++ b/snippets/ruby-rspec/shnredt.snippet @@ -1,2 +1 @@ response.should_not redirect_to(${1:url}) -${2} diff --git a/snippets/ruby-rspec/shnrt.snippet b/snippets/ruby-rspec/shnrt.snippet index c2c5f2c..61ee34f 100644 --- a/snippets/ruby-rspec/shnrt.snippet +++ b/snippets/ruby-rspec/shnrt.snippet @@ -1,2 +1 @@ ${1:target}.should_not respond_to(:${2:sym}) -${3} diff --git a/snippets/ruby-rspec/shnt.snippet b/snippets/ruby-rspec/shnt.snippet index 0353376..c906c27 100644 --- a/snippets/ruby-rspec/shnt.snippet +++ b/snippets/ruby-rspec/shnt.snippet @@ -1,2 +1 @@ lambda { ${1} }.should_not throw_symbol(:${2:symbol}) -${3} diff --git a/snippets/ruby-rspec/shr.snippet b/snippets/ruby-rspec/shr.snippet index 4effa2c..6ca3b86 100644 --- a/snippets/ruby-rspec/shr.snippet +++ b/snippets/ruby-rspec/shr.snippet @@ -1,2 +1 @@ ${1:mock}.should_receive(:${2:message})${3} -${4} diff --git a/snippets/ruby-rspec/shre.snippet b/snippets/ruby-rspec/shre.snippet index 420bbe8..5fb070b 100644 --- a/snippets/ruby-rspec/shre.snippet +++ b/snippets/ruby-rspec/shre.snippet @@ -1,2 +1 @@ ${1:target}.should raise_error(${2:error}) -${3} diff --git a/snippets/ruby-rspec/shredt.snippet b/snippets/ruby-rspec/shredt.snippet index 979c1d6..27befbd 100644 --- a/snippets/ruby-rspec/shredt.snippet +++ b/snippets/ruby-rspec/shredt.snippet @@ -1,2 +1 @@ response.should redirect_to(${1:url}) -${2} diff --git a/snippets/ruby-rspec/shrt.snippet b/snippets/ruby-rspec/shrt.snippet index a796ebd..fee9e3a 100644 --- a/snippets/ruby-rspec/shrt.snippet +++ b/snippets/ruby-rspec/shrt.snippet @@ -1,2 +1 @@ ${1:target}.should respond_to(:${2:sym}) -${3} diff --git a/snippets/ruby-rspec/shtemp.snippet b/snippets/ruby-rspec/shtemp.snippet index 9b08c10..7f2f4a0 100644 --- a/snippets/ruby-rspec/shtemp.snippet +++ b/snippets/ruby-rspec/shtemp.snippet @@ -1,2 +1 @@ response.should render_template(:${1:template}) -${2} diff --git a/snippets/ruby-rspec/wia.snippet b/snippets/ruby-rspec/wia.snippet index 21eda19..e97da4b 100644 --- a/snippets/ruby-rspec/wia.snippet +++ b/snippets/ruby-rspec/wia.snippet @@ -1,2 +1 @@ with(${1:args}) -${2} diff --git a/snippets/ruby-shoulda/samao.snippet b/snippets/ruby-shoulda/samao.snippet deleted file mode 100644 index cfd4e59..0000000 --- a/snippets/ruby-shoulda/samao.snippet +++ /dev/null @@ -1 +0,0 @@ -should_allow_mass_assignment_of :${1:field} diff --git a/snippets/ruby/defi.snippet b/snippets/ruby/defi.snippet index 12c354c..8372de5 100644 --- a/snippets/ruby/defi.snippet +++ b/snippets/ruby/defi.snippet @@ -1,3 +1,2 @@ def initialize${1} - ${2} end diff --git a/snippets/ruby/if.snippet b/snippets/ruby/if.snippet index b2d1e39..b9b99a7 100644 --- a/snippets/ruby/if.snippet +++ b/snippets/ruby/if.snippet @@ -1,3 +1,3 @@ if ${1:condition} - ${2} + ${2} end diff --git a/snippets/support_functions.vim b/snippets/support_functions.vim index a0bb69b..fa10b95 100644 --- a/snippets/support_functions.vim +++ b/snippets/support_functions.vim @@ -23,6 +23,18 @@ function! Snippet_RubySpecNameFromFilename(...) return Snippet_Camelcase(name) endfunction +function! Snippet_RubySpecNameFromFilename(...) + let name = substitute(expand("%:t:r"), '_spec$', '', '') + if len(name) == 0 + if a:0 == 0 + let name = 'MyClass' + else + let name = a:1 + endif + endif + return Snippet_Camelcase(name) +endfunction + function! Snippet_MigrationNameFromFilename(...) let name = substitute(expand("%:t:r"), '^.\{-}_', '', '') if len(name) == 0 @@ -94,6 +106,21 @@ function! Snippet_JavaInstanceVarType(name) return "<+type+>" endfunction +" actionscript {{{1 +function! Snippet_ActionScriptPackageFromPath() + let dir = split(expand("%:p"), "/") + let target_index = 0 + let last_index = -1 + while 1 + let last_index = index(dir, "src", last_index+1, 1) + if last_index != -1 + let target_index = last_index + else + break + endif + endwhile + return join(dir[(target_index+1) : -2], '.') +endfunction "global {{{1 function! s:start_comment() diff --git a/syntax/snippet.vim b/syntax/snippet.vim new file mode 100644 index 0000000..5e919e7 --- /dev/null +++ b/syntax/snippet.vim @@ -0,0 +1,19 @@ +" Syntax highlighting for snippet files (used for snipMate.vim) +" Hopefully this should make snippets a bit nicer to write! +syn match snipComment '^#.*' +syn match placeHolder '\${\d\+\(:.\{-}\)\=}' contains=snipCommand +syn match tabStop '\$\d\+' +syn match snipCommand '`.\{-}`' +syn match snippet '^snippet.*' transparent contains=multiSnipText,snipKeyword +syn match multiSnipText '\S\+ \zs.*' contained +syn match snipKeyword '^snippet'me=s+8 contained +syn match snipError "^[^#s\t].*$" + +hi link snipComment Comment +hi link multiSnipText String +hi link snipKeyword Keyword +hi link snipComment Comment +hi link placeHolder Special +hi link tabStop Special +hi link snipCommand String +hi link snipError Error