Created
June 9, 2012 17:31
-
-
Save tungd/2901890 to your computer and use it in GitHub Desktop.
UltiSnip <tab> everything
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" UtilSnips | |
" The <tab> key works as follow | |
" - if there is popup: <c-n> (next popup item) | |
" - if there is something behind cursor | |
" - try expand snippet | |
" - if can't expand, try jump | |
" - finally try <c-n> (key word completion) | |
" The <s-tab>: | |
" - if there is popup: <c-p> (previous popup item) | |
" - try jump back | |
" - finally try <c-p> (key word completion) | |
if !has('python') | |
let did_UltiSnips_vim=1 | |
endif | |
let g:UltiSnipsEditSplit='horizontal' | |
let g:UltiSnipsExpandTrigger='<c-j>' | |
let g:UltiSnipsExpandJumpForwardTrigger='<c-j>' | |
let g:UltiSnipsExpandJumpBackwardTigger='<c-k>' | |
let g:UltiSnipsExpandJumpBackwardTigger='<s-tab>' | |
let g:UltiSnipsListSnippets='<c-l>' | |
if has('python') | |
python << EOF | |
import vim, os, sys | |
sys.path.append(os.path.expanduser('~/.vim/bundle/vim-ultisnips/plugin')) | |
from UltiSnips import SnippetManager | |
def handle_tab(self): | |
rv = self._try_expand() | |
if not rv: | |
rv = self._jump() | |
if not rv: | |
return '\<c-n>' | |
return '' | |
SnippetManager.handle_tab = handle_tab | |
def handle_shift_tab(self): | |
if not self._jump(True): | |
return '\<c-p>' | |
return '' | |
SnippetManager.handle_shift_tab = handle_shift_tab | |
EOF | |
function! UltiSnips_HandleTab() | |
if pumvisible() | |
return "\<c-n>" | |
endif | |
let col = col('.') - 1 | |
if !col || getline('.')[col - 1] !~ '\k' | |
return "\<tab>" | |
else | |
exec g:_uspy "vim.command('return \"%s\"' % UltiSnips_Manager.handle_tab())" | |
endif | |
endfunction | |
function! UltiSnips_HandleShiftTab() | |
if pumvisible() | |
return "\<c-p>" | |
endif | |
exec g:_uspy "vim.command('return \"%s\"' % UltiSnips_Manager.handle_shift_tab())" | |
endfunction | |
inoremap <tab> <c-r>=UltiSnips_HandleTab()<cr> | |
inoremap <s-tab> <c-r>=UltiSnips_HandleShiftTab()<cr> | |
endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment