mirror of
https://github.com/amix/vimrc
synced 2025-07-31 09:45:00 +08:00
Updated plugins
This commit is contained in:
@ -29,6 +29,7 @@ additional contributions from:
|
||||
* [lpil](https://github.com/lpil)
|
||||
* [marutanm](https://github.com/marutanm)
|
||||
* [MicahElliott](https://github.com/MicahElliott)
|
||||
* [mikeastock](https://github.com/mikeastock)
|
||||
* [muffinresearch](https://github.com/muffinresearch)
|
||||
* [pielgrzym](https://github.com/pielgrzym)
|
||||
* [pose](https://github.com/pose)
|
||||
|
@ -37,17 +37,43 @@ looking at the [vim-snippets][vim-snippets] repository.
|
||||
% git clone https://github.com/honza/vim-snippets.git
|
||||
|
||||
* Using [Vundle][vundle], add the following to your `vimrc` then run
|
||||
`:BundleInstall`
|
||||
`:PluginInstall`
|
||||
|
||||
Bundle "MarcWeber/vim-addon-mw-utils"
|
||||
Bundle "tomtom/tlib_vim"
|
||||
Bundle "garbas/vim-snipmate"
|
||||
Plugin "MarcWeber/vim-addon-mw-utils"
|
||||
Plugin "tomtom/tlib_vim"
|
||||
Plugin "garbas/vim-snipmate"
|
||||
|
||||
" Optional:
|
||||
Bundle "honza/vim-snippets"
|
||||
Plugin "honza/vim-snippets"
|
||||
|
||||
## FAQ ##
|
||||
|
||||
> SnipMate doesn't work / My snippets aren't triggering
|
||||
|
||||
Try all of the following:
|
||||
|
||||
* Check that SnipMate is loaded. This can be done by looking for
|
||||
`<Plug>snipMateTrigger` and similar maps in the output of `:imap`.
|
||||
Additionally make sure either `<Plug>snipMateTrigger` or
|
||||
`<Plug>snipMateNextOrTrigger` is mapped to the key you expect.
|
||||
|
||||
* Check that the snippets file you mean to use exists, and that it contains the
|
||||
snippet you're trying to expand.
|
||||
|
||||
* Check that your snippets file is located inside a `foo/snippets` directory,
|
||||
where `foo` is a path listed in your `runtimepath`.
|
||||
|
||||
* Check that your snippets file is in scope by either the filetype matching the
|
||||
path of the snippet file or the scope explicitly loaded.
|
||||
|
||||
* Check if any snippets from your snippets file are available. This can be done
|
||||
with the "show available snips` map, by default bound to `<C-R><Tab>` in
|
||||
insert mode.
|
||||
|
||||
If all of the above check out, please open an issue stating your Vim version,
|
||||
a sample snippet, and a description of exactly what happens when you try to
|
||||
trigger a snippet.
|
||||
|
||||
> How does SnipMate determine which snippets to load? How can I separate, for
|
||||
> example, my Rails snippets from my Ruby snippets?
|
||||
|
||||
|
@ -331,7 +331,7 @@ function! s:snippet_filenames(scope, trigger) abort
|
||||
let mid = ['', '_*', '/*']
|
||||
let mid += map(copy(mid), "'/' . a:trigger . '*' . v:val")
|
||||
call map(mid, "'snippets/' . a:scope . v:val . '.snippet'")
|
||||
return join(map(mid[:2], 'v:val . "s"') + mid[3:])
|
||||
return map(mid[:2], 'v:val . "s"') + mid[3:]
|
||||
endfunction
|
||||
|
||||
function! snipMate#SetByPath(dict, trigger, path, snippet, bang, snipversion) abort
|
||||
@ -342,12 +342,27 @@ function! snipMate#SetByPath(dict, trigger, path, snippet, bang, snipversion) ab
|
||||
let d[a:trigger][a:path] = [a:snippet, a:snipversion]
|
||||
endfunction
|
||||
|
||||
if v:version < 704 || has('win32')
|
||||
function! s:Glob(path, expr)
|
||||
let res = []
|
||||
for p in split(a:path, ',')
|
||||
let h = split(fnamemodify(a:expr, ':h'), '/')[0]
|
||||
if isdirectory(p . '/' . h)
|
||||
call extend(res, split(glob(p . '/' . a:expr), "\n"))
|
||||
endif
|
||||
endfor
|
||||
return filter(res, 'filereadable(v:val)')
|
||||
endfunction
|
||||
else
|
||||
function! s:Glob(path, expr)
|
||||
return split(globpath(a:path, a:expr), "\n")
|
||||
endfunction
|
||||
endif
|
||||
|
||||
" default triggers based on paths
|
||||
function! snipMate#DefaultPool(scopes, trigger, result) abort
|
||||
let scopes = s:AddScopeAliases(a:scopes)
|
||||
let scopes_done = []
|
||||
let rtp_save = &rtp
|
||||
let &rtp = join(g:snipMate.snippet_dirs, ',')
|
||||
let s:lookup_state = {}
|
||||
let s:lookup_state.snips = []
|
||||
|
||||
@ -356,7 +371,13 @@ function! snipMate#DefaultPool(scopes, trigger, result) abort
|
||||
let s:lookup_state.scope = scope
|
||||
let s:lookup_state.extends = []
|
||||
|
||||
exec 'runtime!' s:snippet_filenames(scope, escape(a:trigger, "*[]?{}`'$|#%"))
|
||||
for expr in s:snippet_filenames(scope, escape(a:trigger, "*[]?{}`'$|#%"))
|
||||
for path in g:snipMate.snippet_dirs
|
||||
for file in s:Glob(path, expr)
|
||||
source `=file`
|
||||
endfor
|
||||
endfor
|
||||
endfor
|
||||
|
||||
call add(scopes_done, scope)
|
||||
call extend(scopes, s:lookup_state.extends)
|
||||
@ -368,8 +389,6 @@ function! snipMate#DefaultPool(scopes, trigger, result) abort
|
||||
call snipMate#SetByPath(a:result, trigger, desc, contents, bang, snipversion)
|
||||
endif
|
||||
endfor
|
||||
|
||||
let &rtp = rtp_save
|
||||
endfunction
|
||||
|
||||
" return a dict of snippets found in runtimepath matching trigger
|
||||
@ -385,64 +404,28 @@ fun! snipMate#GetSnippets(scopes, trigger) abort
|
||||
return result
|
||||
endf
|
||||
|
||||
" adds leading tab
|
||||
" and replaces leading spaces by tabs
|
||||
" see ftplugin/snippet.vim
|
||||
fun! snipMate#RetabSnip() range abort
|
||||
let leadingTab = expand('%:e') == 'snippets'
|
||||
|
||||
let lines = getline(a:firstline, a:lastline)
|
||||
|
||||
" remove leading "\t"
|
||||
let allIndented = 1
|
||||
for l in lines
|
||||
if l[0] != '\t' | let allIndented = 0 | endif
|
||||
endfor
|
||||
|
||||
" retab
|
||||
if allIndented
|
||||
call map(lines, 'v:val[1:]')
|
||||
endif
|
||||
|
||||
let leadingSp = filter(map(copy(lines),'matchstr(v:val,"^\\s*") '),'v:val !=""')
|
||||
if !empty(leadingSp)
|
||||
" lines containing leading spaces found
|
||||
let smallestInd = len(sort(leadingSp)[-1])
|
||||
let ind = input('retab, spaces per tab: ', smallestInd)
|
||||
for i in range(0, len(lines)-1)
|
||||
let ml = matchlist(lines[i], '^\(\s*\)\(.*\)')
|
||||
let lines[i] = repeat("\t", len(ml[1]) / ind)
|
||||
\ . repeat( " ", len(ml[1]) % ind)
|
||||
\ . ml[2]
|
||||
function! snipMate#OpenSnippetFiles() abort
|
||||
let files = []
|
||||
let scopes_done = []
|
||||
let exists = []
|
||||
let notexists = []
|
||||
for scope in s:AddScopeAliases(snipMate#ScopesByFile())
|
||||
let files += split(s:snippet_filenames(scope, ''))
|
||||
endfor
|
||||
endif
|
||||
" readd tab
|
||||
let tab = leadingTab ? "\t" : ""
|
||||
for i in range(0,len(lines)-1)
|
||||
call setline(a:firstline + i, tab.lines[i])
|
||||
endfor
|
||||
endf
|
||||
|
||||
fun! snipMate#OpenSnippetFiles() abort
|
||||
let dict = snipMate#GetSnippetFiles(0, snipMate#ScopesByFile(), '*')
|
||||
" sort by files wether they exist - put existing files first
|
||||
let exists = []
|
||||
let notExists = []
|
||||
for [file, v] in items(dict)
|
||||
let v['file'] = file
|
||||
if v['exists']
|
||||
call add(exists, v)
|
||||
else
|
||||
call add(notExists, v)
|
||||
endif
|
||||
endfor
|
||||
let all = exists + notExists
|
||||
let show = map(copy(all),'(v:val["exists"] ? "exists:" : "does not exist yet:")." ".v:val["file"]')
|
||||
let select = tlib#input#List('mi', 'select files to be opened in splits', show)
|
||||
for idx in select
|
||||
exec 'sp '.all[idx - 1]['file']
|
||||
endfor
|
||||
endf
|
||||
call filter(files, "v:val !~# '\\*'")
|
||||
for path in split(g:snipMate.snippet_dirs, ',')
|
||||
let fullpaths = map(copy(files), 'printf("%s/%s", path, v:val)')
|
||||
let exists += filter(copy(fullpaths), 'filereadable(v:val)')
|
||||
let notexists += map(filter(copy(fullpaths),
|
||||
\ 'v:val =~# "\.snippets" && !filereadable(v:val)'),
|
||||
\ '"does not exist: " . v:val')
|
||||
endfor
|
||||
let all = exists + notexists
|
||||
let select = tlib#input#List('mi', 'select files to be opened in splits', all)
|
||||
for idx in select
|
||||
exec 'sp' all[idx - 1]
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
fun! snipMate#ScopesByFile() abort
|
||||
" duplicates are removed in AddScopeAliases
|
||||
|
@ -1,8 +0,0 @@
|
||||
command! -buffer -range=% RetabSnip <line1>,<line2>call snipMate#RetabSnip()
|
||||
vnoremap <buffer> <cr> :RetabSnip<cr>
|
||||
|
||||
if !exists('g:snippet_no_indentation_settings')
|
||||
setlocal sw=4
|
||||
setlocal tabstop=4
|
||||
setlocal noexpandtab
|
||||
endif
|
@ -1 +1,20 @@
|
||||
runtime! ftplugin/snippet.vim
|
||||
" Vim filetype plugin for SnipMate snippets (.snippets and .snippet files)
|
||||
|
||||
if exists("b:did_ftplugin")
|
||||
finish
|
||||
endif
|
||||
let b:did_ftplugin = 1
|
||||
|
||||
let b:undo_ftplugin = "setl et< sts< cms< fdm< fde<"
|
||||
|
||||
" Use hard tabs
|
||||
setlocal noexpandtab softtabstop=0
|
||||
|
||||
setlocal foldmethod=expr foldexpr=getline(v:lnum)!~'^\\t\\\\|^$'?'>1':1
|
||||
|
||||
setlocal commentstring=#\ %s
|
||||
setlocal nospell
|
||||
|
||||
command! -buffer -range=% RetabSnip
|
||||
\ echom "This command is deprecated. Use :retab and = instead. Doing that now."
|
||||
\ | <line1>,<line2>retab! | <line1>,<line2>normal =
|
||||
|
32
sources_non_forked/vim-snipmate/indent/snippets.vim
Normal file
32
sources_non_forked/vim-snipmate/indent/snippets.vim
Normal file
@ -0,0 +1,32 @@
|
||||
" Simple indent support for SnipMate snippets files
|
||||
|
||||
if exists('b:did_indent')
|
||||
finish
|
||||
endif
|
||||
let b:did_indent = 1
|
||||
|
||||
setlocal nosmartindent
|
||||
setlocal indentkeys=!^F,o,O,=snippet,=version,=extends
|
||||
setlocal indentexpr=GetSnippetIndent()
|
||||
|
||||
if exists("*GetSnippetIndent")
|
||||
finish
|
||||
endif
|
||||
|
||||
function! GetSnippetIndent()
|
||||
let line = getline(v:lnum)
|
||||
let prev_lnum = v:lnum - 1
|
||||
let prev_line = prev_lnum != 0 ? getline(prev_lnum) : ""
|
||||
|
||||
if line =~# '\v^(snippet|extends|version) '
|
||||
return 0
|
||||
elseif indent(v:lnum) > 0
|
||||
return indent(v:lnum)
|
||||
elseif prev_line =~# '^snippet '
|
||||
return &sw
|
||||
elseif indent(prev_lnum) > 0
|
||||
return indent(prev_lnum)
|
||||
endif
|
||||
|
||||
return 0
|
||||
endfunction
|
@ -28,11 +28,12 @@ if (!exists('g:snipMateSources'))
|
||||
let g:snipMateSources['default'] = funcref#Function('snipMate#DefaultPool')
|
||||
endif
|
||||
|
||||
au BufRead,BufNewFile *.snippet set ft=snippet
|
||||
au FileType snippet setl noet nospell
|
||||
|
||||
au BufRead,BufNewFile *.snippets set ft=snippets
|
||||
au FileType snippets setl noet nospell fdm=expr fde=getline(v:lnum)!~'^\\t\\\\|^$'?'>1':1
|
||||
au BufRead,BufNewFile *.snippet,*.snippets setlocal filetype=snippets
|
||||
au FileType snippets if expand('<afile>:e') =~# 'snippet$'
|
||||
\ | setlocal syntax=snippet
|
||||
\ | else
|
||||
\ | setlocal syntax=snippets
|
||||
\ | endif
|
||||
|
||||
inoremap <silent> <Plug>snipMateNextOrTrigger <C-R>=snipMate#TriggerSnippet()<CR>
|
||||
snoremap <silent> <Plug>snipMateNextOrTrigger <Esc>a<C-R>=snipMate#TriggerSnippet()<CR>
|
||||
|
@ -7,10 +7,10 @@ syn match snipEscape '\\\\\|\\`'
|
||||
syn match snipCommand '\%(\\\@<!\%(\\\\\)*\)\@<=`.\{-}\%(\\\@<!\%(\\\\\)*\)\@<=`'
|
||||
syn match snippet '^snippet.*' contains=multiSnipText,snipKeyword
|
||||
syn match snippet '^extends.*' contains=snipKeyword
|
||||
syn match snippet '^guard\s\+.*' contains=multiSnipText,snipKeyword
|
||||
syn match snippet '^version.*' contains=snipKeyword
|
||||
syn match multiSnipText '\S\+ \zs.*' contained
|
||||
syn match snipKeyword '^(snippet|extends)'me=s+8 contained
|
||||
syn match snipError "^[^#se\t].*$"
|
||||
syn match snipKeyword '^(snippet|extends|version)'me=s+8 contained
|
||||
syn match snipError "^[^#vse\t].*$"
|
||||
|
||||
hi link snippet Identifier
|
||||
hi link snipComment Comment
|
||||
|
Reference in New Issue
Block a user