Snippet expansion and word under cursor
- Dominant language
- Vim Script
- Stars
- 10.3k
- Forks
- 608
- Avg merge
- 5d 8h
- Merged PRs (30d)
- 2
Description
- Category
- [ ] Question
- [ ] Bug
- [x] Suggestion
- OS
- [x] Linux
- [ ] macOS
- [ ] Windows
- [ ] Etc.
- Vim
- [x] Vim
- [ ] Neovim
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
```
function! s:inject_snippet(line)
let snip = split(a:line, "\t")[0]
execute 'normal! a'.s:strip(snip)."\=UltiSnips#ExpandSnippet()\"
endfunction
```
to
```
function! s:inject_snippet(line)
let snip = split(a:line, "\t")[0]
execute 'normal! diwi'.s:strip(snip)."\=UltiSnips#ExpandSnippet()\"
endfunction
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.