-
-
Notifications
You must be signed in to change notification settings - Fork 582
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Snippet expansion and word under cursor #796
Comments
Came here looking for this as well, i'd really like for this to work out. |
I observed one additional problem with Both problems seem to be fixed by using the following: function! s:inject_snippet(line)
startinsert
let col = col('.')
if col > 1 && getline('.')[: col-2] =~ "\\S$"
call feedkeys("\<c-w>", 'n')
endif
let snip = split(a:line, "\t")[0]
call feedkeys(s:strip(snip) . "\<c-r>=UltiSnips#ExpandSnippet()\<cr>", 'n')
endfunction together with nnoremap <silent> <C-_> :Snippets<CR>
inoremap <silent> <C-_> <C-\><C-O>:Snippets<CR> Can you folks please test that before I submit a pull request? |
I didn't really like the :startinsert so I figured a better way to fix this: function! s:inject_snippet(line)
let ve = &ve
set ve=onemore
let del = col('.') > 1 && getline('.')[0 : col('.')-2] =~ "\\S$" ? "\<c-w>" : ""
let snip = split(a:line, "\t")[0]
execute 'normal! i'.del.s:strip(snip)
execute 'normal! l'
call UltiSnips#ExpandSnippet()
let &ve = ve
endfunction It feels solid so I submitted a PR right away: #1196 |
Oh crap, invoking UltiSnips#ExpandSnippet via call breaks the select mode. :-( |
I just updated #1196 with a fix for another glitch, and the select mode problem goes away if the insert mode mapping uses
If any of you still have some problems with fzf.vim + UltiSnips, can you perhaps give my PR a try? |
When the Snippet command is called, the word under cursor is automatically used as initial pattern for the search. The problem is that, once a matching is selected, the snippet keyword is inserted after the current word and hence the snippet expansion fails.
For example, if the word under cursor is 'def', one possible suggestion could be 'defm'. Upon selecting the later, the resulting text becomes 'defdefm', which is not a valid snippet keyword.
So perhaps there could be a way to prevent this, either by deleting the current word under cursor before inserting the selected keyword, or by completing the keyword instead of inserting it whole. The former solution is simpler, just replace
to
The text was updated successfully, but these errors were encountered: