2009-07-21 04:21:05 -04:00
|
|
|
" File: UltiSnips.vim
|
|
|
|
" Author: Holger Rapp <SirVer@gmx.de>
|
|
|
|
" Description: The Ultimate Snippets solution for Vim
|
|
|
|
" Last Modified: July 21, 2009
|
|
|
|
"
|
|
|
|
" Testing Info: {{{
|
|
|
|
" Running vim + ultisnips with the absolute bar minimum settings inside a screen session:
|
|
|
|
" $ screen -S vim
|
|
|
|
" $ vim -u NONE -U NONE -c ':set nocompatible' -c ':set runtimepath+=.'
|
|
|
|
" $ ./test.py # launch the testsuite
|
|
|
|
" }}}
|
2009-07-04 10:08:14 -04:00
|
|
|
|
2009-07-26 11:42:40 -04:00
|
|
|
if exists('did_UltiSnips_vim') || &cp || version < 700 || !has("python")
|
2009-07-21 04:21:05 -04:00
|
|
|
finish
|
|
|
|
endif
|
2009-07-04 10:08:14 -04:00
|
|
|
|
2009-07-21 04:21:05 -04:00
|
|
|
" Global Variables {{{
|
|
|
|
|
|
|
|
" The trigger used to expand a snippet.
|
|
|
|
" NOTE: expansion and forward jumping can, but needn't be the same trigger
|
|
|
|
if !exists("g:UltiSnipsExpandTrigger")
|
|
|
|
let g:UltiSnipsExpandTrigger = "<tab>"
|
2009-07-04 10:08:14 -04:00
|
|
|
endif
|
2009-07-21 04:21:05 -04:00
|
|
|
|
|
|
|
" The trigger used to jump forward to the next placeholder.
|
|
|
|
" NOTE: expansion and forward jumping can, but needn't be the same trigger
|
|
|
|
if !exists("g:UltiSnipsJumpForwardTrigger")
|
|
|
|
let g:UltiSnipsJumpForwardTrigger = "<c-j>"
|
|
|
|
endif
|
|
|
|
|
|
|
|
" The trigger to jump backward inside a snippet
|
|
|
|
if !exists("g:UltiSnipsJumpBackwardTrigger")
|
|
|
|
let g:UltiSnipsJumpBackwardTrigger = "<c-k>"
|
|
|
|
endif
|
|
|
|
|
|
|
|
" }}}
|
|
|
|
|
|
|
|
"" FUNCTIONS {{{
|
|
|
|
function! UltiSnips_ExpandSnippet()
|
|
|
|
py UltiSnips_Manager.expand()
|
|
|
|
return ""
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! UltiSnips_ExpandSnippetOrJump()
|
|
|
|
py UltiSnips_Manager.expand_or_jump()
|
|
|
|
return ""
|
2009-07-04 06:15:12 -04:00
|
|
|
endfunction
|
|
|
|
|
2009-07-10 06:47:54 -04:00
|
|
|
function! UltiSnips_JumpBackwards()
|
2009-07-21 04:21:05 -04:00
|
|
|
py UltiSnips_Manager.jump_backwards()
|
|
|
|
return ""
|
2009-07-09 09:30:23 -04:00
|
|
|
endfunction
|
|
|
|
|
2009-07-10 06:47:54 -04:00
|
|
|
function! UltiSnips_JumpForwards()
|
2009-07-21 04:21:05 -04:00
|
|
|
py UltiSnips_Manager.jump_forwards()
|
|
|
|
return ""
|
2009-07-04 06:15:12 -04:00
|
|
|
endfunction
|
|
|
|
|
2009-07-21 04:21:05 -04:00
|
|
|
" }}}
|
2009-07-04 06:15:12 -04:00
|
|
|
|
2009-07-21 04:21:05 -04:00
|
|
|
"" STARTUP CODE {{{
|
2009-07-04 10:08:14 -04:00
|
|
|
|
2009-07-04 06:15:12 -04:00
|
|
|
" Expand our path
|
2009-07-04 10:08:14 -04:00
|
|
|
python << EOF
|
|
|
|
import vim, os, sys
|
|
|
|
|
|
|
|
for p in vim.eval("&runtimepath").split(','):
|
|
|
|
dname = p + os.path.sep + "plugin"
|
2009-07-10 06:47:54 -04:00
|
|
|
if os.path.exists(dname + os.path.sep + "UltiSnips"):
|
2009-07-04 10:08:14 -04:00
|
|
|
if dname not in sys.path:
|
|
|
|
sys.path.append(dname)
|
|
|
|
break
|
|
|
|
|
2009-07-10 06:47:54 -04:00
|
|
|
from UltiSnips import UltiSnips_Manager
|
2009-07-21 04:21:05 -04:00
|
|
|
UltiSnips_Manager.expand_trigger = vim.eval("g:UltiSnipsExpandTrigger")
|
|
|
|
UltiSnips_Manager.forward_trigger = vim.eval("g:UltiSnipsJumpForwardTrigger")
|
|
|
|
UltiSnips_Manager.backward_trigger = vim.eval("g:UltiSnipsJumpBackwardTrigger")
|
2009-07-04 10:08:14 -04:00
|
|
|
EOF
|
2009-07-04 06:15:12 -04:00
|
|
|
|
2009-07-21 04:21:05 -04:00
|
|
|
" Map the keys correctly
|
|
|
|
if g:UltiSnipsExpandTrigger == g:UltiSnipsJumpForwardTrigger
|
|
|
|
exec "inoremap " . g:UltiSnipsExpandTrigger . " <C-R>=UltiSnips_ExpandSnippetOrJump()<cr>"
|
|
|
|
exec "snoremap " . g:UltiSnipsExpandTrigger . " <Esc>:call UltiSnips_ExpandSnippetOrJump()<cr>"
|
|
|
|
else
|
|
|
|
exec "inoremap " . g:UltiSnipsExpandTrigger . " <C-R>=UltiSnips_ExpandSnippet()<cr>"
|
|
|
|
exec "snoremap " . g:UltiSnipsExpandTrigger . " <Esc>:call UltiSnips_ExpandSnippet()<cr>"
|
|
|
|
exec "inoremap " . g:UltiSnipsJumpForwardTrigger . " <C-R>=UltiSnips_JumpForwards()<cr>"
|
|
|
|
exec "snoremap " . g:UltiSnipsJumpForwardTrigger . " <Esc>:call UltiSnips_JumpForwards()<cr>"
|
|
|
|
endif
|
|
|
|
exec "inoremap " . g:UltiSnipsJumpBackwardTrigger . " <C-R>=UltiSnips_JumpBackwards()<cr>"
|
|
|
|
exec "snoremap " . g:UltiSnipsJumpBackwardTrigger . " <Esc>:call UltiSnips_JumpBackwards()<cr>"
|
2009-07-06 17:09:53 -04:00
|
|
|
|
|
|
|
" Do not remap this.
|
2009-07-10 06:47:54 -04:00
|
|
|
snoremap <BS> <Esc>:py UltiSnips_Manager.backspace_while_selected()<cr>
|
2009-07-04 06:15:12 -04:00
|
|
|
|
2009-07-10 06:47:54 -04:00
|
|
|
au CursorMovedI * py UltiSnips_Manager.cursor_moved()
|
|
|
|
au InsertEnter * py UltiSnips_Manager.entered_insert_mode()
|
2009-07-21 04:21:05 -04:00
|
|
|
|
|
|
|
let did_UltiSnips_vim=1
|
|
|
|
|
|
|
|
" }}}
|