1
0
mirror of https://github.com/amix/vimrc synced 2025-06-16 09:35:01 +08:00

Updated all plugins that are non-forked. Added some new plugins.

Added update_plugins.py which can fetch new plugins from GitHub.

New plugins added: zencoding, vim-indent-object, taglist, nginx.vim
This commit is contained in:
amix
2013-04-13 14:45:21 -03:00
parent 5731b3a420
commit 3f1cdba799
1057 changed files with 33631 additions and 10806 deletions

View File

@ -2,8 +2,17 @@
snipmate.vim
============
IMPORTANT: comment on: [What about merging whith Ultisnip using its engine](https://github.com/garbas/vim-snipmate/issues/114)
status: snipmate-snippet files are read by Ultisnip flawlessly. See
snipmate-snippets readme about how to configure and use Ultisnips as alternative
That branch also supports completion menu now
Thus there is only one reason left to keep using snipmate from my point of
view: not having python support.
In other words: upstream of snipmate is almost dead. (Better to say Marc Weber is not going to fix any bugs anymore)
:Author: `Michael Sanders`_
:Maintainer: `Rok Garbas`_
:Maintainer: `Adnan Zafar`_ & `Rok Garbas`_ & `Marc Weber`_
:Homepage: http://www.vim.org/scripts/script.php?script_id=2540
:Contributors: `MarcWeber`_, `lilydjwg`_, `henrik`_, `steveno`_, `asymmetric`_, `jherdman`_, `ironcamel`_, `honza`_, `jb55`_, `robhudson`_, `kozo2`_, `MicahElliott`_, `darkwise`_, `redpill`_, `thisgeek`_, `sickill`_, `pose`_, `marutanm`_, `r00k`_, `jbernard`_, `holizz`_, `muffinresearch`_, `statik`_, `taq`_, `alderz`_, `pielgrzym`_
@ -11,79 +20,46 @@ snipmate.vim
.. contents::
Changelog
ChangeLog
=========
1.0 [Unreleased]
----------------
0.85 [2013-04-03]
-----------------
* Split snippet files into separate git repository (github/honza/snipmate-snippets). [2011-06-20, `honza`_]
See 'Snippets repository' below.
* Allow trigger key customization
* Enable undoing of snippet expansion
* Support backslash escaping in snippets
* Add support for {VISUAL}
* Expand filetype extension with scope_aliases
* Add expansion guards
* Enable per-buffer expansion of snippets
* Fix 'cpo' compatibility
* Update supertab compatibility
* Enable customization of various things through g:snipMate
* Adding general snippets to ``css.snippets`` and ``htmldjango.snippets``
[2011-06-10, `pielgrzym`_]
* Disable spelling in snippet files
* Highlight trigger names in .snippets files
* Adding ``css.snippets`` from `tisho`_
(https://github.com/tisho/css-snippets-snipmate)
[2011-04-17, `garbas`_]
* Update many snippets
* Separate sample snippets into separate repository
* Lots of updates to snippets.
* Made the trigger key configurable, https://github.com/garbas/vim-snipmate/pull/4.
[2011-04-13, `thenoseman`_]
* Handle single-line or multiline snippets.
[2011-03-22, `johnbintz`_]
* If there is only one snippet choose it directly.
[2011-03-16, `blueyed`_]
* Add snippets file for "diff" filetype and add bang to function
definitons, allowing for reload.
[2011-03-06, `blueyed`_]
* Update snipmate to handle latest supertab version.
[2011-02-09, `ervandew`_]
* Updated README: added contributors, instructions how to install snipMate,
some spellchecking of my wonderful English, added this Changelog
[2011-02-07, `garbas`_]
* Fixed bug: When leaving a placeholder unchanged and trying to jump to the
next placeholder, the text of the first placeholder would get cleared.
[2011-06-16, `jgosmann`_]
* From below mentioned merges I must specially mention `MarcWeber`_'s patch
which brought quite a few functionalities/improvements:
- snippets are loaded lazily.
- snippets are no longer cached. Thus you always get the snippets you
just wrote to a file without reloading anything.
- When visually selecting a snippet in a .snippets file you can press
<cr> to replace spaces by tabs automatically in a smart way.
Big +1 to `MarcWeber`_ for this. Important to note is that we now depend
on `vim-addon-mw-utils`_ and `tlib`_.
[2011-02-02, `garbas`_]
* Merged pull requests of `MarcWeber`_, `lilydjwg`_, `henrik`_, `steveno`_,
`asymmetric`_, `jherdman`_, `ironcamel`_, `honza`_, `jb55`_,
`robhudson`_, `kozo2`_, `MicahElliott`_, `darkwise`_, `redpill`_,
`thisgeek`_, `sickill`_, `pose`_,
[2011-02-02, `garbas`_]
0.84
----
* Unreleased version by `Michael Sanders`_. Available on `GitHub`_.
0.83 [2009-07-13]
-----------------
* last release done by `Michael Sanders`_, you can find it here:
http://www.vim.org/scripts/download_script.php?src_id=11006
* Last release done by `Michael Sanders`_. Available on `vim.org`_.
How to install
==============
Unfortunately there are many ways to how to install vim plugins. If you don't
see your preferred way of installation plugins please consider updating
Unfortunately there are many ways to install vim plugins. If you don't
see your preferred way of installation, please consider updating
this section. Basically, installation consists of 2 simple steps:
1. Install vim-snipmate
@ -92,7 +68,7 @@ this section. Basically, installation consists of 2 simple steps:
snipmate dependencies
==============
Important to note is that since version 1.0 we depend on this 2 vim plugins:
Important to note is that since version 0.85 we depend on 2 vim plugins:
* `vim-addon-mw-utils`_ providing the implementation for caching parsed
.snippets files.
@ -106,12 +82,11 @@ Important to note is that since version 1.0 we depend on this 2 vim plugins:
Using `VAM`_ (recommended)
------------
::
- Add `snipmate-snippets` to the names to be installed. Or use
"github:name/repo" if you want to use a non standard upstream.
Add snipmate-snippets to the names to be installed. Or use
"github:name/repo" if you want to use a non standard upstream.
The default snippets depend on "snipmate" so VAM will fetch the core along
with its dependencies automatically
The default snippets depend on "snipmate" so VAM will fetch the core along
with its dependencies automatically.
Using `pathogen`_
--------------------------------------
@ -126,7 +101,7 @@ Using `pathogen`_
# Install dependencies:
% git clone https://github.com/tomtom/tlib_vim.git
% git clone https://github.com/MarcWeber/vim-addon-mw-utils.git
% git clone https://github.com/honza/snipmate-snippets.git
% git clone https://github.com/honza/vim-snippets.git
Using `Vundle`_
---------------
@ -136,7 +111,7 @@ Using `Vundle`_
Install dependencies:
Bundle "MarcWeber/vim-addon-mw-utils"
Bundle "tomtom/tlib_vim"
Bundle "honza/snipmate-snippets"
Bundle "honza/vim-snippets"
Install:
Bundle "garbas/vim-snipmate"
@ -150,7 +125,7 @@ Manually (not recommended!)
::
% git clone git://github.com/honza/snipmate-snippets.git
% git clone git://github.com/honza/vim-snippets.git
% git clone git://github.com/garbas/vim-snipmate.git
% cd snipmate.vim
% cp -R * ~/.vim
@ -166,20 +141,13 @@ Snippets repository
There is now one snippet repo containing almost all snippets. You are
encouraged to submit any fixes and new snippets there.
https://github.com/honza/snipmate-snippets
https://github.com/honza/vim-snippets
We also encourage people to maintain sets of snippets for particular use cases.
That all users can benefit from them people can list their snippet repositories here:
* https://github.com/rbonvall/snipmate-snippets-bib (snippets for BibTeX files)
Installation using VAM: "github:rbonvall/snipmate-snippets-bib"
More snippet repositories are listed at that repository's README file.
Why forking snipMate?
=====================
::
After several unsuccessful attempts of contacting Michael Sanders, no
commits in last half year and long pull request line on github (none of
pull requests were commented/replied/rejected) I decided to take action,
@ -197,18 +165,22 @@ Why forking snipMate?
Maybe I will only maintain it for a while until Michael Sanders takes things
back into his hand or until some other super-hero shows up.
Tnx and happy snipmating, Rok Garbas, 2011-02-02
Tnx and happy snipmating, Rok Garbas & Marc Weber, 2011-02-02
related work
=============
See doc/snipMate.txt
Known Bugs
=============
* Set one value default as input of another value.
https://github.com/garbas/vim-snipmate/issues/59
[2011-10-18, `bogdan`_]
TODO / Future
=============
@ -230,8 +202,17 @@ TODO / Future
If you volunteer tell me so that I can reference the link.
[2011-02-02, `MarcWeber`_]
* tcomment claims to know which language mode you're editing in even if its
JS in PHP or HTML within PHP. It would be great if that functionality could be
moved into its own plugirn (vim-detect-language-at-cursor) or such.
Then a lot of the scoped_aliases (which causes collisions easily) could
be enhanced.
.. _`Michael Sanders`: http://www.vim.org/account/profile.php?user_id=16544
.. _`Adnan Zafar`: https://github.com/ajzafar
.. _`Rok Garbas`: rok@garbas.si
.. _`Marc Weber`: marco-oweber@gmx.de
.. _`VAM`: https://github.com/MarcWeber/vim-addon-manager
.. _`pathogen`: http://www.vim.org/scripts/script.php?script_id=2332
.. _`vim-addon-mw-utils`: https://github.com/MarcWeber/vim-addon-mw-utils
@ -270,4 +251,6 @@ TODO / Future
.. _`tisho`: https://github.com/tisho
.. _`pielgrzym`: https://github.com/pielgrzym
.. _`jgosmann`: https://github.com/jgosmann
.. _`taq': https://github.com/taq
.. _`taq`: https://github.com/taq
.. _`vim.org`: http://www.vim.org/scripts/script.php?script_id=2540
.. _`GitHub`: http://github.com/msanders/snipmate.vim

View File

@ -2,8 +2,8 @@
"name" : "snipMate",
"version" : "dev",
"author" : "Michael Sanders -> original project http://github.com/msanders/snipmate.vim",
"maintainer" : "Marc Weber <marco-oweber@gmx.de> (I maintain this fork only)",
"repository" : {"type": "git", "url": "git://github.com/MarcWeber/snipMate.vim.git"},
"maintainer" : "Rok Garbas / Marc Weber",
"repository" : {"type": "git", "url": "git://github.com/garbas/vim-snipmate.git"},
"dependencies" : {
"vim-addon-mw-utils": {},
"tlib": {}

View File

@ -4,6 +4,9 @@ if !exists('loaded_snips') || exists('s:did_snips_mappings')
finish
endif
let s:did_snips_mappings = 1
" save and reset 'cpo'
let s:save_cpo = &cpo
set cpo&vim
" This is put here in the 'after' directory in order for snipMate to override
" other plugin mappings (e.g., supertab).
@ -15,13 +18,13 @@ if !exists('g:snips_trigger_key')
endif
if !exists('g:snips_trigger_key_backwards')
let g:snips_trigger_key_backwards = '<s-' . substitute(g:snips_trigger_key, '[<>]', '', 'g')
let g:snips_trigger_key_backwards = '<s-' . substitute(g:snips_trigger_key, '[<>]', '', 'g') . '>'
endif
exec 'ino <silent> ' . g:snips_trigger_key . ' <c-g>u<c-r>=snipMate#TriggerSnippet()<cr>'
exec 'ino <silent> ' . g:snips_trigger_key . ' <c-r>=snipMate#TriggerSnippet()<cr>'
exec 'snor <silent> ' . g:snips_trigger_key . ' <esc>i<right><c-r>=snipMate#TriggerSnippet()<cr>'
exec 'ino <silent> ' . g:snips_trigger_key_backwards . '> <c-r>=snipMate#BackwardsSnippet()<cr>'
exec 'snor <silent> ' . g:snips_trigger_key_backwards . '> <esc>i<right><c-r>=snipMate#BackwardsSnippet()<cr>'
exec 'ino <silent> ' . g:snips_trigger_key_backwards . ' <c-r>=snipMate#BackwardsSnippet()<cr>'
exec 'snor <silent> ' . g:snips_trigger_key_backwards . ' <esc>i<right><c-r>=snipMate#BackwardsSnippet()<cr>'
exec 'ino <silent> <c-r>' . g:snips_trigger_key . ' <c-r>=snipMate#ShowAvailableSnips()<cr>'
" maybe there is a better way without polluting registers ?
@ -45,4 +48,7 @@ if empty(snippets_dir)
finish
endif
" restore 'cpo'
let &cpo = s:save_cpo
" vim:noet:sw=4:ts=4:ft=vim

View File

@ -10,6 +10,9 @@ catch /.*/
echoe "you're missing tlib. See install instructions at ".expand('<sfile>:h:h').'/README.rst'
endtry
" match $ which doesn't follow a \
let s:d = '\%([\\]\@<!\$\)'
" disable write cache in files
" some people get errors about writing the cache files. Probably there is no
@ -24,7 +27,6 @@ let s:c.scope_aliases = get(s:c, 'scope_aliases', {})
let s:c.scope_aliases.objc = get(s:c.scope_aliases, 'objc', 'c')
let s:c.scope_aliases.cpp = get(s:c.scope_aliases, 'cpp', 'c')
let s:c.scope_aliases.cu = get(s:c.scope_aliases, 'cu', 'c')
let s:c.scope_aliases.cs = get(s:c.scope_aliases, 'cs','c')
let s:c.scope_aliases.xhtml = get(s:c.scope_aliases, 'xhtml', 'html')
let s:c.scope_aliases.html = get(s:c.scope_aliases, 'html', 'javascript')
let s:c.scope_aliases.php = get(s:c.scope_aliases, 'php', 'php,html,javascript')
@ -43,14 +45,12 @@ fun! Filename(...)
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
let s:state_proto = {}
fun! s:state_proto.remove()
unlet! b:snip_state
" Remove all buffer-local autocommands in the snipmate_changes group
au! snipmate_changes * <buffer>
endf
fun! snipMate#expandSnip(snip, col)
@ -61,7 +61,7 @@ fun! snipMate#expandSnip(snip, col)
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 snipLines = split(substitute(snippet, ''.s:d .'\d\+\|'.s:d .'{\d\+.\{-}}', '', 'g'), "\n", 1)
let line = getline(lnum)
let afterCursor = strpart(line, col - 1)
@ -86,23 +86,18 @@ fun! snipMate#expandSnip(snip, col)
" 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)
let b:snip_state = copy(s:state_proto)
let [b:snip_state.stops, b:snip_state.stop_count] = s:BuildTabStops(snippet, lnum, col - indent, indent)
if s:snipLen
aug snipMateAutocmds
au CursorMovedI * call s:UpdateChangedSnip(0)
au InsertEnter * call s:UpdateChangedSnip(1)
if b:snip_state.stop_count
aug snipmate_changes
au CursorMovedI,InsertEnter <buffer> call b:snip_state.update_changes()
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 b:snip_state.set_stop(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
return b:snip_state.select_word()
else
unl g:snipPos s:snipLen
unlet b:snip_state
" 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)
@ -111,6 +106,18 @@ fun! snipMate#expandSnip(snip, col)
return ''
endf
" Update state information to correspond to the given tab stop
function! s:state_proto.set_stop(stop)
let self.stop_no = a:stop
let self.cur_stop = self.stops[self.stop_no]
let self.end_col = self.cur_stop[1] + self.cur_stop[2]
let self.start_col = self.cur_stop[1]
call cursor(self.cur_stop[0], self.cur_stop[1])
let self.prev_len = col('$')
let self.has_vars = exists('self.cur_stop[3]')
let self.old_vars = self.has_vars ? deepcopy(self.cur_stop[3]) : []
endfunction
" Prepare snippet to be processed by s:BuildTabStops
fun! s:ProcessSnippet(snip)
let snippet = a:snip
@ -147,16 +154,16 @@ fun! s:ProcessSnippet(snip)
" 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')
let snippet = substitute(snippet, s:d.'{\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}')
while snippet =~ s:d.'{'.i
let s = matchstr(snippet, s:d.'{'.i.':\zs.\{-}\ze}')
if s != ''
let snippet = substitute(snippet, '$'.i, s.'&', 'g')
let snippet = substitute(snippet, s:d.i, s.'&', 'g')
endif
let i += 1
endw
@ -184,7 +191,7 @@ endf
" (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.
" (e.g. "${1:foo}" would return 3).
" 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,
@ -193,30 +200,30 @@ 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')
while a:snip =~ s:d.'{'.i
let beforeTabStop = matchstr(withoutVars, '^.*\ze'.s:d .'{'.i.'\D')
let withoutOthers = substitute(withoutVars, ''.s:d .'{\('.i.'\D\)\@!\d\+.\{-}}', '', 'g')
let j = i - 1
call add(snipPos, [0, 0, -1])
call add(snipPos, [0, 0, 0])
let snipPos[j][0] = a:lnum + s:Count(beforeTabStop, "\n")
let snipPos[j][1] = a:indent + len(matchstr(withoutOthers, '.*\(\n\|^\)\zs.*\ze${'.i.'\D'))
let snipPos[j][1] = a:indent + len(matchstr(withoutOthers, '.*\(\n\|^\)\zs.*\ze'.s:d .'{'.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}'))
if withoutVars =~ ''.s:d .'{'.i.':'
let snipPos[j][2] = len(matchstr(withoutVars, ''.s:d .'{'.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\|$\)')
let withoutOthers = substitute(a:snip, ''.s:d .'{\d\+.\{-}}\|'.s:d .''.i.'\@!\d\+', '', 'g')
while match(withoutOthers, ''.s:d .''.i.'\(\D\|$\)') != -1
let beforeMark = matchstr(withoutOthers, '^.\{-}\ze'.dots.''.s:d .''.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\|$\)', '', '')
let withoutOthers = substitute(withoutOthers, ''.s:d .''.i.'\ze\(\D\|$\)', '', '')
endw
endif
let i += 1
@ -224,65 +231,48 @@ fun! s:BuildTabStops(snip, lnum, col, indent)
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
function! s:state_proto.jump_stop(backwards)
" Update changes just in case
" This seems to be only needed because insert completion does not trigger
" the CursorMovedI event
call self.update_changes()
if exists('s:update')
call s:UpdatePlaceholderTabStops()
else
call s:UpdateTabStops()
endif
" Update stop and var locations
call self.update_stops()
" 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
" Store the changed col/length of the current stop
let self.cur_stop[1] = self.start_col
let self.cur_stop[2] = self.end_col - self.start_col
let s:curPos += a:backwards ? -1 : 1
let self.stop_no += 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 self.stop_no < 0 | let self.stop_no = self.stop_count - 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 ? "\<tab>" : snipMate#TriggerSnippet()
if self.stop_no == self.stop_count
call self.remove()
return -1
endif
call cursor(g:snipPos[s:curPos][0], g:snipPos[s:curPos][1])
call self.set_stop(self.stop_no)
return self.select_word()
endfunction
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
" Updates tab stops/vars
function! s:state_proto.update_stops()
let changeLen = self.end_col - self.cur_stop[2] - self.start_col
" 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
for pos in self.stops
if pos == self.cur_stop | continue | endif
let changed = pos[0] == curLine && pos[1] > self.start_col
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
for [lnum, col] in self.old_vars
if lnum > pos[0] | break | endif
if pos[0] == lnum
if pos[1] > col || (pos[2] == -1 && pos[1] == col)
@ -292,202 +282,95 @@ fun! s:UpdatePlaceholderTabStops()
endif
endif
endfor
let pos[1] -= changeLen * changed
let pos[2] -= changeLen * changedVars " Parse variables within placeholders
" e.g., "${1:foo} ${2:$1bar}"
let pos[1] += changeLen * changed
" Parse variables within placeholders, e.g., "${1:foo} ${2:$1bar}"
let pos[2] += changeLen * changedVars
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
if exists('pos[3]')
for nPos in pos[3]
let changed = nPos[0] == curLine && nPos[1] > self.start_col
for [lnum, col] in self.old_vars
if lnum > nPos[0] | break | endif
if nPos[0] == lnum && nPos[1] > col
let changed += 1
endif
endfor
let nPos[1] += changeLen * changed
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 <cr> 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
endfunction
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
" Select the placeholder for the current tab stop
function! s:state_proto.select_word()
let len = self.cur_stop[2]
if !len | return '' | endif
let l = col('.') != 1 ? 'l' : ''
if &sel == 'exclusive'
return "\<esc>".l.'v'.s:origWordLen."l\<c-g>"
return "\<esc>".l.'v'.len."l\<c-g>"
endif
return s:origWordLen == 1 ? "\<esc>".l.'gh'
\ : "\<esc>".l.'v'.(s:origWordLen - 1)."l\<c-g>"
endf
return len == 1 ? "\<esc>".l.'gh' : "\<esc>".l.'v'.(len - 1)."l\<c-g>"
endfunction
" 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
" Update the snippet as text is typed. The self.update_vars() function does
" the actual work.
" If the cursor moves outside of a placeholder, call self.remove()
function! s:state_proto.update_changes()
let change_len = col('$') - self.prev_len
let self.end_col += change_len
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
let col = col('.')
if line('.') != self.cur_stop[0] || col < self.start_col || col > self.end_col
call self.remove()
endif
let changeLen = g:snipPos[s:curPos][2] - newWordLen
if self.has_vars
call self.update_vars(change_len)
endif
let self.prev_len = col('$')
endfunction
" Actually update the vars for any changed text
function! s:state_proto.update_vars(change)
let newWordLen = self.end_col - self.start_col
let newWord = strpart(getline('.'), self.start_col - 1, newWordLen)
let changeLen = a:change
let curLine = line('.')
let startCol = col('.')
let oldStartSnip = s:startCol
let oldStartSnip = self.start_col
let updateTabStops = changeLen != 0
let i = 0
for [lnum, col] in g:snipPos[s:curPos][3]
for [lnum, col] in self.cur_stop[3]
if updateTabStops
let start = s:startCol
let start = self.start_col
if lnum == curLine && col <= start
let s:startCol -= changeLen
let s:endCol -= changeLen
let self.start_col += changeLen
let self.end_col += changeLen
endif
for nPos in g:snipPos[s:curPos][3][(i):]
for nPos in self.cur_stop[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
let nPos[1] += changeLen
endif
endfor
if lnum == curLine && col > start
let col -= changeLen
let g:snipPos[s:curPos][3][i][1] = col
let col += changeLen
let self.cur_stop[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, '\&'), ''))
let theline = getline(lnum)
" subtract -1 to go from column byte index to string byte index
" subtract another -1 to exclude the col'th element
call setline(lnum, theline[0:(col-2)] . newWord . theline[(col+self.end_col-self.start_col-a:change-1):])
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
endfunction
" should be moved to utils or such?
fun! snipMate#SetByPath(dict, path, value)
@ -506,7 +389,7 @@ endf
fun! snipMate#ReadSnippetsFile(file)
let result = []
if !filereadable(a:file) | return result | endif
let r_guard = 'guard\s\+\zs.*'
let r_guard = '^guard\s\+\zs.*'
let inSnip = 0
let guard = 1
for line in readfile(a:file) + ["\n"]
@ -565,7 +448,19 @@ endf
fun! s:Glob(dir, file)
let f = a:dir.a:file
if a:dir =~ '\*' || isdirectory(a:dir)
return split(glob(escape(f,"{}")),"\n")
" vim's glob() is somewhat unreliable since it uses the
" user's current shell which may accept different patterns
" (POSIX vs. zsh vs. bash vs. ...). On my system, that
" leads to glob() sometimes returning files that don't
" exist, so filter the returned list to make sure that the
" files really exist in the filesystem.
let res = split(glob(escape(f,"{}")), "\n")
if !empty(res)
return filter(res, 'filereadable(v:val)')
else
return []
endif
else
return filereadable(f) ? [f] : []
endif
@ -650,7 +545,7 @@ fun! snipMate#DefaultPool(scopes, trigger, result)
for [f,opts] in items(snipMate#GetSnippetFiles(1, a:scopes, a:trigger))
if opts.type == 'snippets'
for [trigger, name, contents, guard] in cached_file_contents#CachedFileContents(f, s:c.read_snippets_cached, 0)
if trigger !~ triggerR | continue | endif
if trigger !~ escape(triggerR,'~') | continue | endif
if snipMate#EvalGuard(guard)
call snipMate#SetByPath(a:result, [trigger, opts.name_prefix.' '.name], contents)
endif
@ -809,23 +704,11 @@ fun! s:ChooseSnippet(snippets)
endf
fun! snipMate#ShowAvailableSnips()
let line = getline('.')
let col = col('.')
let word = matchstr(line, '\S\+\%'.col.'c')
let matchlen = 0
let matches = []
let word = matchstr(getline('.'), '\S\+\%'.col.'c')
let snippet_triggers = map(snipMate#GetSnippetsForWordBelowCursor(word, '*', 0),'v:val[0]')
for trigger in snippet_triggers
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
let snippets = map(snipMate#GetSnippetsForWordBelowCursor(word, '*', 0),'v:val[0]')
let matches = filter(snippets, "v:val =~# '\\V\\^" . escape(word, '\') . "'")
" Pretty hacky, but really can't have the tab swallowed!
if len(matches) == 0
@ -833,10 +716,7 @@ fun! snipMate#ShowAvailableSnips()
return ""
endif
" 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, sort(matches))
call complete(col - len(word), sort(matches))
return ''
endf
@ -870,7 +750,12 @@ fun! snipMate#TriggerSnippet()
call feedkeys("\<tab>") | return ''
endif
if exists('g:snipPos') | return snipMate#jumpTabStop(0) | endif
if exists('b:snip_state')
let jump = b:snip_state.jump_stop(0)
if type(jump) == 1 " returned a string
return jump
endif
endif
let word = matchstr(getline('.'), '\S\+\%'.col('.').'c')
let list = snipMate#GetSnippetsForWordBelowCursor(word, '', 1)
@ -886,7 +771,8 @@ fun! snipMate#TriggerSnippet()
let snippet = s
end
let &undolevels = &undolevels " create new undo point
" Before expanding snippet, create new undo point |i_CTRL-G|
let &undolevels = &undolevels
let col = col('.') - len(trigger)
sil exe 's/\V'.escape(trigger, '/\.').'\%#//'
return snipMate#expandSnip(snippet, col)
@ -904,7 +790,7 @@ endf
fun! snipMate#BackwardsSnippet()
if exists('g:snipPos') | return snipMate#jumpTabStop(1) | endif
if exists('b:snip_state') | return b:snip_state.jump_stop(1) | endif
if exists('g:SuperTabMappingForward')
if g:SuperTabMappingForward == "<s-tab>"

View File

@ -49,6 +49,8 @@ There are some alternatives:
- ultisnips (python based)
- xptemplate which is probably a much more powerful
but also more complex
- neosnippets - which seems to be able to read snippet
files when swiching on compatible mode
- (..?)
snipmate is not perfect - however it gets its job done perfectly and gets out
@ -113,8 +115,8 @@ The parsed .snippets files are cached.
in the current buffer to show a list via.
------------------------------------------------------------------------------
SNIPPET SOURCES *snippet-sources*
==============================================================================
SNIPPET SOURCES *snipMate-snippet-sources*
snipMate is configurable.
@ -178,7 +180,7 @@ More details about all possible relative locations to |rtp| can be found in
SYNTAX *snippet-syntax* *snipMate-syntax*
Default snippet sources [1], you can add your own as illustrated in
|snippet-sources|.
|snipMate-snippet-sources|.
trigger: the snippet's name.
|rtp| : Vim's |runtimepath| path list
@ -409,6 +411,7 @@ Perhaps some of these features will be added in a later release.
CONTACT *snipMate-contact* *snipMate-author*
current maintainers:
- Adnan Zafar
- garbas
- Marc Weber (marco-oweber@gmx.de)
You should consider creating a github ticket or contacting us because the

View File

@ -1,6 +1,6 @@
" File: snipMate.vim
" Author: Michael Sanders
" Version: 0.84
" Version: 0.85
" 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>".