UltiSnips/plugin/UltiSnips.vim

78 lines
1.9 KiB
VimL
Raw Normal View History

"" FUNCTIONS
2009-07-10 06:47:54 -04:00
function! UltiSnips_ExpandSnippet()
if exists('g:SuperTabMappingForward')
if g:SuperTabMappingForward == "<s-tab>"
let SuperTabKey = "\<c-n>"
elseif g:SuperTabMappingBackward == "<s-tab>"
let SuperTabKey = "\<c-p>"
endif
endif
if pumvisible() " Update snippet if completion is used, or deal with supertab
if exists('SuperTabKey')
call feedkeys(SuperTabKey) | return ''
endif
call feedkeys("\<esc>a", 'n') " Close completion menu
call feedkeys("\<tab>") | return ''
endif
" Now, really expand something
2009-07-04 06:15:12 -04:00
py << EOF
2009-07-10 06:47:54 -04:00
if not UltiSnips_Manager.try_expand():
vim.command("""if exists('SuperTabKey')
call feedkeys(SuperTabKey)
endif
""")
2009-07-04 06:15:12 -04:00
EOF
return ""
2009-07-04 06:15:12 -04:00
endfunction
2009-07-10 06:47:54 -04:00
function! UltiSnips_JumpBackwards()
2009-07-04 06:15:12 -04:00
py << EOF
2009-07-10 06:47:54 -04:00
UltiSnips_Manager.jump(True)
EOF
return ""
endfunction
2009-07-10 06:47:54 -04:00
function! UltiSnips_JumpForwards()
py << EOF
2009-07-10 06:47:54 -04:00
UltiSnips_Manager.jump()
2009-07-04 06:15:12 -04:00
EOF
return ""
endfunction
"" STARTUP CODE
2009-07-04 06:15:12 -04:00
" Expand our path
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"):
if dname not in sys.path:
sys.path.append(dname)
break
2009-07-10 06:47:54 -04:00
from UltiSnips import UltiSnips_Manager
EOF
2009-07-04 06:15:12 -04:00
2009-07-06 17:09:53 -04:00
" You can remap these
2009-07-10 06:47:54 -04:00
inoremap <Tab> <C-R>=UltiSnips_ExpandSnippet()<cr>
snoremap <Tab> <Esc>:call UltiSnips_ExpandSnippet()<cr>
inoremap <C-k> <C-R>=UltiSnips_JumpBackwards()<cr>
snoremap <C-k> <Esc>:call UltiSnips_JumpBackwards()<cr>
inoremap <C-j> <C-R>=UltiSnips_JumpForwards()<cr>
snoremap <C-j> <Esc>:call UltiSnips_JumpForwards()<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-04 06:15:12 -04:00