summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2010-03-16 13:10:35 -0500
committerJesse Luehrs <doy@tozt.net>2010-03-16 13:10:35 -0500
commite64c9e5b1db135eeb850a7e459f0785f0da40e4f (patch)
treedbe4ef0ad38d72e837308c0dfedde3ddf1d3739c
parent6644cf44f25dfba0c7a23a06e681dba856bbd4d6 (diff)
downloadconf-e64c9e5b1db135eeb850a7e459f0785f0da40e4f.tar.gz
conf-e64c9e5b1db135eeb850a7e459f0785f0da40e4f.zip
update snipmate
-rw-r--r--vim/after/plugin/snipMate.vim17
-rw-r--r--vim/autoload/snipMate.vim203
-rw-r--r--vim/doc/snipMate.txt25
-rw-r--r--vim/plugin/snipMate.vim50
-rw-r--r--vim/snippets/c.snippets24
-rw-r--r--vim/snippets/cpp.snippets4
-rw-r--r--vim/snippets/html.snippets2
-rw-r--r--vim/snippets/java.snippets16
-rw-r--r--vim/snippets/objc.snippets47
-rw-r--r--vim/snippets/perl.snippets20
-rw-r--r--vim/snippets/php.snippets4
-rw-r--r--vim/snippets/python.snippets11
-rw-r--r--vim/snippets/sh.snippets2
-rw-r--r--vim/snippets/vim.snippets2
-rw-r--r--vim/syntax/snippet.vim2
15 files changed, 279 insertions, 150 deletions
diff --git a/vim/after/plugin/snipMate.vim b/vim/after/plugin/snipMate.vim
index 1d995ef..03e79ae 100644
--- a/vim/after/plugin/snipMate.vim
+++ b/vim/after/plugin/snipMate.vim
@@ -1,24 +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('s:did_snips_mappings') || &cp || version < 700
+if !exists('loaded_snips') || exists('s:did_snips_mappings')
finish
endif
let s:did_snips_mappings = 1
ino <silent> <tab> <c-r>=TriggerSnippet()<cr>
snor <silent> <tab> <esc>i<right><c-r>=TriggerSnippet()<cr>
+ino <silent> <s-tab> <c-r>=BackwardsSnippet()<cr>
+snor <silent> <s-tab> <esc>i<right><c-r>=BackwardsSnippet()<cr>
ino <silent> <c-r><tab> <c-r>=ShowAvailableSnips()<cr>
+
+" 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 <bs> b<bs>
-snor ' b<bs>'
snor <right> <esc>a
snor <left> <esc>bi
+snor ' b<bs>'
+snor ` b<bs>`
+snor % b<bs>%
+snor U b<bs>U
+snor ^ b<bs>^
+snor \ b<bs>\
+snor <c-x> b<bs><c-x>
" By default load snippets in snippets_dir
if empty(snippets_dir)
finish
endif
-call GetSnippets(snippets_dir, '_') " Get global snippets
+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/vim/autoload/snipMate.vim b/vim/autoload/snipMate.vim
index e0219e3..dcd28f6 100644
--- a/vim/autoload/snipMate.vim
+++ b/vim/autoload/snipMate.vim
@@ -5,19 +5,28 @@ fun! Filename(...)
endf
fun s:RemoveSnippet()
- unl g:snipPos s:curPos s:snipLen s:endSnip s:endSnipLine s:prevLen
+ 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
@@ -34,14 +43,21 @@ fun snipMate#expandSnip(snip, col)
" 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
- let s:curPos = 0
- let s:endSnip = g:snipPos[s:curPos][1]
- let s:endSnipLine = g:snipPos[s:curPos][0]
+ 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('$')]
@@ -56,6 +72,7 @@ fun snipMate#expandSnip(snip, col)
return ''
endf
+" Prepare snippet to be processed by s:BuildTabStops
fun s:ProcessSnippet(snip)
let snippet = a:snip
" Evaluate eval (`...`) expressions.
@@ -81,7 +98,7 @@ fun s:ProcessSnippet(snip)
while stridx(snippet, '${'.i) != -1
let s = matchstr(snippet, '${'.i.':\zs.\{-}\ze}')
if s != ''
- let snippet = substitute(snippet, '$'.i, '&'.s, 'g')
+ let snippet = substitute(snippet, '$'.i, s.'&', 'g')
endif
let i += 1
endw
@@ -92,6 +109,7 @@ fun s:ProcessSnippet(snip)
return snippet
endf
+" Counts occurences of haystack in needle
fun s:Count(haystack, needle)
let counter = 0
let index = stridx(a:haystack, a:needle)
@@ -102,8 +120,7 @@ fun s:Count(haystack, needle)
return counter
endf
-" This function builds a list of a list of each tab stop in the
-" snippet containing:
+" 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
@@ -120,28 +137,28 @@ fun s:BuildTabStops(snip, lnum, col, indent)
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\+.\{-}}', '', 'g')
- let snipPos += [[a:lnum + s:Count(beforeTabStop, "\n"),
- \ a:indent + len(matchstr(withoutOthers,
- \ "^.*\\(\n\\|^\\)\\zs.*\\ze${".i.'\D')), -1]]
- if snipPos[i-1][0] == a:lnum
- let snipPos[i-1][1] += a:col
- endif
+ 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 j = i - 1
let snipPos[j][2] = len(matchstr(withoutVars, '${'.i.':\zs.\{-}\ze}'))
- let snipPos[j] += [[]]
+ 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$'.i.'\D')
- let linecount = a:lnum + s:Count(beforeMark, "\n")
- let snipPos[j][3] += [[linecount,
- \ a:indent + (linecount > a:lnum
- \ ? len(matchstr(beforeMark, "^.*\n\\zs.*"))
- \ : a:col + len(beforeMark))]]
- let withoutOthers = substitute(withoutOthers, '$'.i.'\ze\D', '', '')
+ 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
@@ -149,45 +166,65 @@ fun s:BuildTabStops(snip, lnum, col, indent)
return [snipPos, i - 1]
endf
-fun snipMate#jumpTabStop()
+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
- let s:curPos += 1
+ " 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:endSnip == g:snipPos[s:curPos-1][1]+g:snipPos[s:curPos-1][2]
+ let sMode = s:endCol == g:snipPos[s:curPos-1][1]+g:snipPos[s:curPos-1][2]
call s:RemoveSnippet()
return sMode ? "\<tab>" : TriggerSnippet()
endif
call cursor(g:snipPos[s:curPos][0], g:snipPos[s:curPos][1])
- let s:endSnipLine = g:snipPos[s:curPos][0]
- let s:endSnip = g:snipPos[s:curPos][1]
- let s:prevLen = [line('$'), col('$')]
+ 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:startSnip s:origWordLen s:update
- if !exists('s:origPos') | return | endif
+ 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[s:curPos + 1:]
- let changed = pos[0] == curLine && pos[1] > s:origSnipPos
+ 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:origPos
+ 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)
@@ -204,8 +241,8 @@ fun s:UpdatePlaceholderTabStops()
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:origSnipPos
- for [lnum, col] in s:origPos
+ 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
@@ -215,23 +252,23 @@ fun s:UpdatePlaceholderTabStops()
endfor
endfor
endif
- unl s:endSnip s:origPos s:origSnipPos
+ unl s:endCol s:oldVars s:oldEndCol
endf
fun s:UpdateTabStops()
- let changeLine = s:endSnipLine - g:snipPos[s:curPos][0]
- let changeCol = s:endSnip - g:snipPos[s:curPos][1]
+ 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]
+ let col = g:snipPos[s:curPos][1]
" Update the line number of all proceeding tab stops if <cr> has
" been inserted.
if changeLine != 0
let changeLine -= 1
- for pos in g:snipPos[s:curPos + 1:]
+ for pos in g:snipPos
if pos[0] >= lnum
if pos[0] == lnum | let pos[1] += changeCol | endif
let pos[0] += changeLine
@@ -247,7 +284,7 @@ fun s:UpdateTabStops()
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[s:curPos + 1:]
+ for pos in g:snipPos
if pos[1] >= col && pos[0] == lnum
let pos[1] += changeCol
endif
@@ -264,13 +301,13 @@ 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: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:endSnip = -1
- let s:startSnip = g:snipPos[s:curPos][1] - 1
+ 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' : ''
@@ -289,53 +326,57 @@ endf
"
" It also automatically quits the snippet if the cursor is moved out of it
" while in insert mode.
-au CursorMovedI * call s:UpdateChangedSnip(0)
-au InsertEnter * call s:UpdateChangedSnip(1)
fun s:UpdateChangedSnip(entering)
- if exists('s:update') " If modifying a placeholder
- if !exists('s:origPos') && s:curPos + 1 < s:snipLen
+ 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:startSnip must be saved too, in case text is added
+ " 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:origSnipPos = s:startSnip
- let s:origPos = deepcopy(g:snipPos[s:curPos][3])
+ let s:oldEndCol = s:startCol
+ let s:oldVars = deepcopy(g:snipPos[s:curPos][3])
endif
let col = col('.') - 1
- if s:endSnip != -1
+ if s:endCol != -1
let changeLen = col('$') - s:prevLen[1]
- let s:endSnip += changeLen
+ let s:endCol += changeLen
else " When being updated the first time, after leaving select mode
if a:entering | return | endif
- let s:endSnip = col - 1
+ let s:endCol = col - 1
endif
" If the cursor moves outside the snippet, quit it
- if line('.') != g:snipPos[s:curPos][0] || col < s:startSnip ||
- \ col - 1 > s:endSnip
- unl! s:startSnip s:origWordLen s:origPos s:update
+ 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')
- let col = col('.')
- let lnum = line('.')
+ 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:endSnipLine
- let s:endSnip += col('$') - s:prevLen[1]
+ if lnum == s:endLine
+ let s:endCol += col('$') - s:prevLen[1]
let s:prevLen = [line('$'), col('$')]
endif
if changeLine != 0
- let s:endSnipLine += changeLine
- let s:endSnip = col
+ let s:endLine += changeLine
+ let s:endCol = col
endif
" Delete snippet if cursor moves out of it in insert mode
- if (lnum == s:endSnipLine && (col > s:endSnip || col < g:snipPos[s:curPos][1]))
- \ || lnum > s:endSnipLine || lnum < g:snipPos[s:curPos][0]
+ 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
@@ -344,25 +385,25 @@ 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:endSnip - s:startSnip + 1
- let newWord = strpart(getline('.'), s:startSnip, newWordLen)
+ 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:startSnip
+ 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
+ let i = 0
for [lnum, col] in g:snipPos[s:curPos][3]
if updateTabStops
- let start = s:startSnip
+ let start = s:startCol
if lnum == curLine && col <= start
- let s:startSnip -= changeLen
- let s:endSnip -= changeLen
+ 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.
@@ -382,8 +423,8 @@ fun s:UpdateVars()
call setline(lnum, substitute(getline(lnum), '\%'.col.'c\V'.
\ escape(s:oldWord, '\'), escape(newWord, '\&'), ''))
endfor
- if oldStartSnip != s:startSnip
- call cursor(0, startCol + s:startSnip - oldStartSnip)
+ if oldStartSnip != s:startCol
+ call cursor(0, startCol + s:startCol - oldStartSnip)
endif
let s:oldWord = newWord
diff --git a/vim/doc/snipMate.txt b/vim/doc/snipMate.txt
index 1d86877..704d44a 100644
--- a/vim/doc/snipMate.txt
+++ b/vim/doc/snipMate.txt
@@ -1,7 +1,7 @@
*snipMate.txt* Plugin for using TextMate-style snippets in Vim.
snipMate *snippet* *snippets* *snipMate*
-Last Change: May 8, 2009
+Last Change: July 13, 2009
|snipMate-description| Description
|snipMate-syntax| Snippet syntax
@@ -33,14 +33,19 @@ you type "for<tab>" in insert mode, it will expand a typical for loop in C: >
To go to the next item in the loop, simply <tab> 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.
+snippet will be updated. To go in reverse, use <shift-tab>.
==============================================================================
SYNTAX *snippet-syntax*
Snippets can be defined in two ways. They can be in their own file, named
after their trigger in 'snippets/<filetype>/<trigger>.snippet', or they can be
-defined together in a 'snippets/<filetype>.snippets' file.
+defined together in a 'snippets/<filetype>.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: >
@@ -221,14 +226,14 @@ spaces. If 'softtabstop' is not set, 'shiftwidth' is used instead.
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 shift-tab, just change this: >
+to CTRL-J, just change this: >
ino <tab> <c-r>=TriggerSnippet()<cr>
snor <tab> <esc>i<right><c-r>=TriggerSnippet()<cr>
to this: >
- ino <s-tab> <c-r>=TriggerSnippet()<cr>
- snor <s-tab> <esc>i<right><c-r>=TriggerSnippet()<cr>
+ ino <c-j> <c-r>=TriggerSnippet()<cr>
+ snor <c-j> <esc>i<right><c-r>=TriggerSnippet()<cr>
==============================================================================
FEATURES *snipMate-features*
@@ -243,15 +248,15 @@ snipMate.vim has the following features among others:
- 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"
+ - [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 way to go back a tab stop, like shift-tab in TextMate.
- There is no $0; the order of tab stops must be explicitly stated.
- Placeholders within placeholders are not possible. E.g.: >
@@ -276,4 +281,6 @@ To contact the author (Michael Sanders), please email:
I greatly appreciate any suggestions or improvements offered for the script.
+==============================================================================
+
vim:tw=78:ts=8:ft=help:norl:
diff --git a/vim/plugin/snipMate.vim b/vim/plugin/snipMate.vim
index fe0c8a1..3efee2a 100644
--- a/vim/plugin/snipMate.vim
+++ b/vim/plugin/snipMate.vim
@@ -1,7 +1,7 @@
" File: snipMate.vim
" Author: Michael Sanders
-" Version: 0.81
-" Last Modified: May 15, 2009
+" 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 "<tab>".
@@ -17,7 +17,7 @@ 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
+au FileType snippet setl noet fdm=indent
let s:snippets = {} | let s:multi_snips = {}
@@ -139,7 +139,7 @@ fun! TriggerSnippet()
call feedkeys("\<tab>") | return ''
endif
- if exists('g:snipPos') | return snipMate#jumpTabStop() | endif
+ if exists('g:snipPos') | return snipMate#jumpTabStop(0) | endif
let word = matchstr(getline('.'), '\S\+\%'.col('.').'c')
for scope in [bufnr('%')] + split(&ft, '\.') + ['_']
@@ -148,7 +148,7 @@ fun! TriggerSnippet()
" the snippet.
if snippet != ''
let col = col('.') - len(trigger)
- sil exe 's/\V'.escape(trigger, '/').'\%#//'
+ sil exe 's/\V'.escape(trigger, '/.').'\%#//'
return snipMate#expandSnip(snippet, col)
endif
endfor
@@ -160,6 +160,23 @@ fun! TriggerSnippet()
return "\<tab>"
endf
+fun! BackwardsSnippet()
+ if exists('g:snipPos') | return snipMate#jumpTabStop(1) | endif
+
+ if exists('g:SuperTabMappingForward')
+ if g:SuperTabMappingBackward == "<s-tab>"
+ let SuperTabKey = "\<c-p>"
+ elseif g:SuperTabMappingForward == "<s-tab>"
+ let SuperTabKey = "\<c-n>"
+ endif
+ endif
+ if exists('SuperTabKey')
+ call feedkeys(SuperTabKey)
+ return ''
+ endif
+ return "\<s-tab>"
+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)
@@ -175,6 +192,9 @@ fun s:GetSnippet(word, scope)
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
@@ -190,17 +210,19 @@ fun s:ChooseSnippet(scope, trigger)
return num == -1 ? '' : s:multi_snips[a:scope][a:trigger][num][1]
endf
-fun ShowAvailableSnips()
- let word = matchstr(getline('.'), '\S\+\%'.col('.').'c')
+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 matchpos = 0
+ let matchlen = 0
let matches = []
for scope in [bufnr('%')] + split(&ft, '\.') + ['_']
- let triggers = exists('s:snippets["'.scope.'"]') ? keys(s:snippets[scope]) : []
- if exists('s:multi_snips["'.scope.'"]')
+ 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
@@ -210,12 +232,16 @@ fun ShowAvailableSnips()
elseif trigger =~ '^'.word
let matches += [trigger]
let len = len(word)
- if len > matchpos | let matchpos = len | endif
+ if len > matchlen | let matchlen = len | endif
endif
endfor
endfor
endfor
- call complete(col('.') - matchpos, matches)
+
+ " 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/vim/snippets/c.snippets b/vim/snippets/c.snippets
index dd16668..8824329 100644
--- a/vim/snippets/c.snippets
+++ b/vim/snippets/c.snippets
@@ -18,6 +18,14 @@ snippet Def
#endif${3}
snippet def
#define
+snippet ifdef
+ #ifdef ${1:FOO}
+ ${2:#define }
+ #endif
+snippet #if
+ #if ${1:FOO}
+ ${2}
+ #endif
# Header Include-Guard
snippet once
#ifndef ${1:`toupper(Filename('', 'UNTITLED').'_H')`}
@@ -64,9 +72,12 @@ snippet fun
{
${4:/* code */}
}
+# Function Declaration
+snippet fund
+ ${1:void} ${2:function_name}(${3});${4}
# Typedef
snippet td
- typedef ${1:int} ${2:MyCustomType};
+ typedef ${1:int} ${2:MyCustomType};${3}
# Struct
snippet st
struct ${1:`Filename('$1_t', 'name')`} {
@@ -74,9 +85,14 @@ snippet st
}${3: /* optional variable list */};${4}
# Typedef struct
snippet tds
- typedef struct ${2:$1 }{
+ typedef struct ${2:_$1 }{
${3:/* data */}
} ${1:`Filename('$1_t', 'name')`};
+# Typdef enum
+snippet tde
+ typedef enum {
+ ${1:/* data */}
+ } ${2:foo};
# printf
# unfortunately version this isn't as nice as TextMates's, given the lack of a
# dynamic `...`
@@ -85,3 +101,7 @@ snippet pr
# fprintf (again, this isn't as nice as TextMate's version, but it works)
snippet fpr
fprintf(${1:stderr}, "${2:%s}\n"${3});${4}
+snippet .
+ [${1}]${2}
+snippet un
+ unsigned
diff --git a/vim/snippets/cpp.snippets b/vim/snippets/cpp.snippets
index 4a3b7c7..65fe5e1 100644
--- a/vim/snippets/cpp.snippets
+++ b/vim/snippets/cpp.snippets
@@ -24,7 +24,7 @@ snippet cl
public:
$1(${2:arguments});
virtual ~$1();
-
+
private:
${3:/* data */}
};
@@ -33,5 +33,5 @@ snippet forv
for (std::vector<${1:int}>::const_iterator ${2:it} = ${3:vec}.begin();
$2 != $3.end();
++$2) {
- ${4:/* code */}
+ ${4:/* code */}
}
diff --git a/vim/snippets/html.snippets b/vim/snippets/html.snippets
index 5abc731..aefb9db 100644
--- a/vim/snippets/html.snippets
+++ b/vim/snippets/html.snippets
@@ -115,7 +115,7 @@ snippet head
${2}
</head>
snippet title
- <title>${1:`substitute(Filename("", "Page Title"), "^.", "\u&", "")`}</title>${2}
+ <title>${1:`substitute(Filename('', 'Page Title'), '^.', '\u&', '')`}</title>${2}
snippet script
<script type="text/javascript" charset="utf-8">
${1}
diff --git a/vim/snippets/java.snippets b/vim/snippets/java.snippets
index 4fb84b7..fd705cb 100644
--- a/vim/snippets/java.snippets
+++ b/vim/snippets/java.snippets
@@ -4,21 +4,21 @@ snippet main
${1:/* code */}
}
snippet pu
- public
+ public
snippet po
- protected
+ protected
snippet pr
- private
+ private
snippet st
- static
+ static
snippet fi
- final
+ final
snippet ab
- abstract
+ abstract
snippet re
- return
+ return
snippet br
- break;
+ break;
snippet de
default:
${1}
diff --git a/vim/snippets/objc.snippets b/vim/snippets/objc.snippets
index 7c2cd6a..4749bb7 100644
--- a/vim/snippets/objc.snippets
+++ b/vim/snippets/objc.snippets
@@ -1,8 +1,8 @@
# #import <...>
-snippet imp
+snippet Imp
#import <${1:Cocoa/Cocoa.h}>${2}
# #import "..."
-snippet Imp
+snippet imp
#import "${1:`Filename()`.h}"${2}
# @selector(...)
snippet sel
@@ -12,10 +12,10 @@ snippet s
@"${1}"${2}
# Object
snippet o
- ${1:NSObject} *${2:foo} = [${3:$1 alloc}];${5}
+ ${1:NSObject} *${2:foo} = [${3:$1 alloc}]${4};${5}
# NSLog(...)
snippet log
- NSLog(@"${1}"${2});${3}
+ NSLog(@"${1:%@}"${2});${3}
# Class
snippet objc
@interface ${1:`Filename('', 'someClass')`} : ${2:NSObject}
@@ -28,10 +28,10 @@ snippet objc
@end
# Class Interface
snippet int
- @interface ${1:`Filename('', 'someClass')`}
- {${2}
+ @interface ${1:`Filename('', 'someClass')`} : ${2:NSObject}
+ {${3}
}
- ${3}
+ ${4}
@end
# Class Implementation
snippet impl
@@ -41,11 +41,14 @@ snippet impl
snippet init
- (id)init
{
- if ((self = [super init]))
- {${1}
- }
+ [super init];
return self;
}
+snippet ifself
+ if (self = [super init]) {
+ ${1:/* code */}
+ }
+ return self;
snippet ibo
IBOutlet ${1:NSSomeClass} *${2:$1};${3}
# Category
@@ -74,19 +77,19 @@ snippet bez
snippet m
- (${1:id})${2:method}
{
- ${3:return self;}
+ ${3}
}
# Method declaration
snippet md
- (${1:id})${2:method};${3}
# IBAction declaration
snippet ibad
- - (IBAction)${1:method};${2}
+ - (IBAction)${1:method}:(${2:id})sender;${3}
# IBAction method
snippet iba
- - (IBAction)${1:method}
+ - (IBAction)${1:method}:(${2:id})sender
{
- ${2}
+ ${3}
}
# awakeFromNib method
snippet wake
@@ -130,8 +133,8 @@ snippet objacc
$2 = $3;
}${4}
# for (object in array)
-snippet fora
- for (${1:Class} *${2:Object} in ${3:array}) {
+snippet forin
+ for (${1:Class} *${2:some$1} in ${3:array}) {
${4}
}
snippet forarray
@@ -144,13 +147,13 @@ snippet forarray
# IBOutlet
# @property (Objective-C 2.0)
snippet prop
- @property (${1:retain}) ${2:NSSomeClass} *${3:$2};${4}
+ @property (${1:retain}) ${2:NSSomeClass} ${3:*$2};${4}
# @synthesize (Objective-C 2.0)
snippet syn
@synthesize ${1:property};${2}
# [[ alloc] init]
snippet alloc
- [[${1:foo} alloc] init]${2};${3}
+ [[${1:foo} alloc] init${2}];${3}
# retain
snippet ret
[${1:foo} retain];${2}
@@ -165,7 +168,7 @@ snippet arel
snippet pool
NSAutoreleasePool *${1:pool} = [[NSAutoreleasePool alloc] init];
${2:/* code */}
- [$1 release];
+ [$1 drain];
# Throw an exception
snippet except
NSException *${1:badness};
@@ -173,3 +176,9 @@ snippet except
reason:@"${3}"
userInfo:nil];
[$1 raise];
+snippet prag
+ #pragma mark ${1:foo}
+snippet cl
+ @class ${1:Foo};${2}
+snippet color
+ [[NSColor ${1:blackColor}] set];
diff --git a/vim/snippets/perl.snippets b/vim/snippets/perl.snippets
index f123666..01f6a0e 100644
--- a/vim/snippets/perl.snippets
+++ b/vim/snippets/perl.snippets
@@ -2,21 +2,31 @@
snippet #!
#!/usr/bin/env perl
+# Hash Pointer
+snippet .
+ =>
snippet sub
sub ${1:foo} {
${2}
}
snippet if
- if (${1:cond}) {
- ${2}
+ if (${1}) {
+ ${2:# body...}
+ }
+snippet ife
+ if (${1}) {
+ ${2:# body...}
+ }
+ else {
+ ${3:# else...}
}
snippet elsif
- elsif (${1:cond}) {
- ${2}
+ elsif (${1:}) {
+ ${2:# else...}
}
snippet else
else {
- ${1}
+ ${1:# else...}
}
snippet for
for my $${1:var} (${2:1..10}) {
diff --git a/vim/snippets/php.snippets b/vim/snippets/php.snippets
index 46420da..3ce9e26 100644
--- a/vim/snippets/php.snippets
+++ b/vim/snippets/php.snippets
@@ -3,7 +3,7 @@ snippet php
${1}
?>
snippet ec
- echo "${1:string}";${2}
+ echo "${1:string}"${2};
snippet inc
include '${1:file}';${2}
snippet inc1
@@ -119,7 +119,7 @@ snippet doc_h
* @copyright ${4:$2}, `strftime('%d %B, %Y')`
* @package ${5:default}
**/
-
+
/**
* Define DocBlock
*//
diff --git a/vim/snippets/python.snippets b/vim/snippets/python.snippets
index 70e0e16..d511184 100644
--- a/vim/snippets/python.snippets
+++ b/vim/snippets/python.snippets
@@ -1,6 +1,8 @@
snippet #!
#!/usr/bin/python
+snippet imp
+ import ${1:module}
# Module Docstring
snippet docs
'''
@@ -27,9 +29,12 @@ snippet def
def ${1:fname}(${2:`indent('.') ? 'self' : ''`}):
"""${3:docstring for $1}"""
${4:pass}
+snippet deff
+ def ${1:fname}(${2:`indent('.') ? 'self' : ''`}):
+ ${3}
# New Method
snippet defs
- def ${1:mname}(self, ${2:arg})):
+ def ${1:mname}(self, ${2:arg}):
${3:pass}
# New Property
snippet property
@@ -39,7 +44,9 @@ snippet property
${3:return self._$1}
def fset(self, value):
${4:self._$1 = value}
-
+# Lambda
+snippet ld
+ ${1:var} = lambda ${2:vars} : ${3:action}
snippet .
self.
snippet try Try/Except
diff --git a/vim/snippets/sh.snippets b/vim/snippets/sh.snippets
index 8e3851b..f035126 100644
--- a/vim/snippets/sh.snippets
+++ b/vim/snippets/sh.snippets
@@ -1,7 +1,7 @@
# #!/bin/bash
snippet #!
#!/bin/bash
-
+
snippet if
if [[ ${1:condition} ]]; then
${2:#statements}
diff --git a/vim/snippets/vim.snippets b/vim/snippets/vim.snippets
index 0bb03af..64e7807 100644
--- a/vim/snippets/vim.snippets
+++ b/vim/snippets/vim.snippets
@@ -3,8 +3,6 @@ snippet header
" Author: ${2:`g:snips_author`}
" Description: ${3}
${4:" Last Modified: `strftime("%B %d, %Y")`}
-snippet lm
- " Last Modified: `strftime("%B %d, %Y")`
snippet guard
if exists('${1:did_`Filename()`}') || &cp${2: || version < 700}
finish
diff --git a/vim/syntax/snippet.vim b/vim/syntax/snippet.vim
index 8edf70d..5e919e7 100644
--- a/vim/syntax/snippet.vim
+++ b/vim/syntax/snippet.vim
@@ -5,7 +5,7 @@ syn match placeHolder '\${\d\+\(:.\{-}\)\=}' contains=snipCommand
syn match tabStop '\$\d\+'
syn match snipCommand '`.\{-}`'
syn match snippet '^snippet.*' transparent contains=multiSnipText,snipKeyword
-syn match multiSnipText '\w\+ \zs.*' contained
+syn match multiSnipText '\S\+ \zs.*' contained
syn match snipKeyword '^snippet'me=s+8 contained
syn match snipError "^[^#s\t].*$"