1
0
Fork 0
mirror of synced 2024-11-27 03:05:36 -05:00
ultimate-vim/sources_non_forked/vim-snipmate/plugin/snipMate.vim

137 lines
4.9 KiB
VimL
Raw Normal View History

2012-08-16 23:41:25 -04:00
" File: snipMate.vim
" 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>".
"
" For more help see snipMate.txt; you can do this by using:
" :helptags ~/.vim/doc
2014-01-06 19:25:41 -05:00
" :h SnipMate
2012-08-16 23:41:25 -04:00
if exists('loaded_snips') || &cp || version < 700
finish
endif
let loaded_snips = 1
2014-04-18 08:58:02 -04:00
" Save and reset 'cpo'
2013-04-26 12:17:22 -04:00
let s:save_cpo = &cpo
set cpo&vim
2012-08-16 23:41:25 -04:00
try
call funcref#Function('')
catch /.*/
2013-08-03 08:50:12 -04:00
echoe "you're missing vim-addon-mw-utils. See install instructions at ".expand('<sfile>:h:h').'/README.md'
2012-08-16 23:41:25 -04:00
endtry
if (!exists('g:snipMateSources'))
let g:snipMateSources = {}
2014-04-18 08:58:02 -04:00
" Default source: get snippets based on runtimepath
2012-08-16 23:41:25 -04:00
let g:snipMateSources['default'] = funcref#Function('snipMate#DefaultPool')
endif
2015-03-14 16:02:10 -04:00
au BufRead,BufNewFile *.snippet,*.snippets setlocal filetype=snippets
au FileType snippets if expand('<afile>:e') =~# 'snippet$'
\ | setlocal syntax=snippet
\ | else
\ | setlocal syntax=snippets
\ | endif
2012-08-16 23:41:25 -04:00
2013-04-26 12:17:22 -04:00
inoremap <silent> <Plug>snipMateNextOrTrigger <C-R>=snipMate#TriggerSnippet()<CR>
snoremap <silent> <Plug>snipMateNextOrTrigger <Esc>a<C-R>=snipMate#TriggerSnippet()<CR>
inoremap <silent> <Plug>snipMateTrigger <C-R>=snipMate#TriggerSnippet(1)<CR>
2013-04-26 12:17:22 -04:00
inoremap <silent> <Plug>snipMateBack <C-R>=snipMate#BackwardsSnippet()<CR>
snoremap <silent> <Plug>snipMateBack <Esc>a<C-R>=snipMate#BackwardsSnippet()<CR>
inoremap <silent> <Plug>snipMateShow <C-R>=snipMate#ShowAvailableSnips()<CR>
2014-04-18 08:58:02 -04:00
xnoremap <silent> <Plug>snipMateVisual :<C-U>call <SID>grab_visual()<CR>gv"_c
2013-04-26 12:17:22 -04:00
2014-04-18 08:58:02 -04:00
" config variables
if !exists('g:snips_author')
let g:snips_author = 'Me'
endif
2012-08-16 23:41:25 -04:00
if !exists('g:snipMate')
2014-04-18 08:58:02 -04:00
let g:snipMate = {}
endif
" SnipMate inserts this string when no snippet expansion can be done
let g:snipMate['no_match_completion_feedkeys_chars'] =
\ get(g:snipMate, 'no_match_completion_feedkeys_chars', "\t")
" Add default scope aliases, without overriding user settings
let g:snipMate.scope_aliases = get(g:snipMate, 'scope_aliases', {})
2014-07-02 07:18:18 -04:00
if exists('g:snipMate_no_default_aliases')
echom 'The g:snipMate_no_default_aliases option has been renamed.'
\ 'See :h snipMate-options.'
endif
if (!exists('g:snipMate_no_default_aliases') || !g:snipMate_no_default_aliases)
\ && (!exists('g:snipMate.no_default_aliases')
\ || !g:snipMate.no_default_aliases)
let g:snipMate.scope_aliases.objc =
\ get(g:snipMate.scope_aliases, 'objc', 'c')
let g:snipMate.scope_aliases.cpp =
\ get(g:snipMate.scope_aliases, 'cpp', 'c')
let g:snipMate.scope_aliases.cu =
\ get(g:snipMate.scope_aliases, 'cu', 'c')
let g:snipMate.scope_aliases.xhtml =
\ get(g:snipMate.scope_aliases, 'xhtml', 'html')
let g:snipMate.scope_aliases.html =
\ get(g:snipMate.scope_aliases, 'html', 'javascript')
let g:snipMate.scope_aliases.php =
\ get(g:snipMate.scope_aliases, 'php', 'php,html,javascript')
let g:snipMate.scope_aliases.ur =
\ get(g:snipMate.scope_aliases, 'ur', 'html,javascript')
let g:snipMate.scope_aliases.mxml =
\ get(g:snipMate.scope_aliases, 'mxml', 'actionscript')
let g:snipMate.scope_aliases.eruby =
\ get(g:snipMate.scope_aliases, 'eruby', 'eruby-rails,html')
let g:snipMate.scope_aliases.scss =
\ get(g:snipMate.scope_aliases, 'scss', 'css')
let g:snipMate.scope_aliases.less =
\ get(g:snipMate.scope_aliases, 'less', 'css')
2012-08-16 23:41:25 -04:00
endif
2014-04-18 08:58:02 -04:00
let g:snipMate['get_snippets'] = get(g:snipMate, 'get_snippets', funcref#Function("snipMate#GetSnippets"))
2012-08-16 23:41:25 -04:00
2014-04-18 08:58:02 -04:00
" List of paths where snippets/ dirs are located, or a function returning such
" a list
2015-02-04 05:43:54 -05:00
let g:snipMate['snippet_dirs'] = get(g:snipMate, 'snippet_dirs', split(&rtp, ','))
if type(g:snipMate['snippet_dirs']) != type([])
echohl WarningMsg
echom "g:snipMate['snippet_dirs'] must be a List"
echohl None
2013-07-17 19:06:05 -04:00
endif
2012-08-16 23:41:25 -04:00
" _ is default scope added always
"
" &ft honors multiple filetypes and syntax such as in set ft=html.javascript syntax=FOO
2014-04-18 08:58:02 -04:00
let g:snipMate['get_scopes'] = get(g:snipMate, 'get_scopes', funcref#Function('return split(&ft,"\\.")+[&syntax, "_"]'))
2012-08-16 23:41:25 -04:00
2013-08-03 08:50:12 -04:00
" Modified from Luc Hermitte's function on StackOverflow
" <http://stackoverflow.com/a/1534347>
function! s:grab_visual() abort
2013-08-03 08:50:12 -04:00
let a_save = @a
try
2014-04-18 08:58:02 -04:00
normal! gv"ay
2015-02-04 05:43:54 -05:00
let b:snipmate_visual = @a
2013-08-03 08:50:12 -04:00
finally
let @a = a_save
endtry
endfunction
2014-07-02 07:18:18 -04:00
" TODO: Allow specifying an arbitrary snippets file
function! s:load_scopes(bang, ...) abort
2014-04-18 08:58:02 -04:00
let gb = a:bang ? g: : b:
let gb.snipMate = get(gb, 'snipMate', {})
let gb.snipMate.scope_aliases = get(gb.snipMate, 'scope_aliases', {})
let gb.snipMate.scope_aliases['_'] = join(split(get(gb.snipMate.scope_aliases, '_', ''), ',') + a:000, ',')
endfunction
2014-08-03 18:02:51 -04:00
command! -bang -bar -nargs=+ SnipMateLoadScope
2014-04-18 08:58:02 -04:00
\ call s:load_scopes(<bang>0, <f-args>)
" Edit snippet files
command! SnipMateOpenSnippetFiles call snipMate#OpenSnippetFiles()
2013-04-26 12:17:22 -04:00
" restore 'cpo'
let &cpo = s:save_cpo
2012-08-16 23:41:25 -04:00
" vim:noet:sw=4:ts=4:ft=vim