ultisnips
ultisnips copied to clipboard
Autoexpansion of snippets doesn't always work when YCM is enabled
When using UltiSnips along with YCM, autoexpanding snippets doesn't always work as expected. I've spent a lot of time trying to figure out the exact circumstances, and think that this issue appears exactly when there is text before (the first occurrence of) the first tab stop jumped to (usually $1 or $0) which is on the same line, and the tab stop is not separated from that text by two or more non-alphanumeric characters.
Expected behavior: Snippet autoexpands as usual
Actual behavior: In the scenario described above, suppose we have a snippet where the first tab stop is marked by $1. In the first occurrence of $1, all the text in that line which precedes the tab stop is replaced by the trigger word. Furthermore, for any other occurrences of $1, the trigger word is added where the tab stop would be. (As a note, this is only for tab stops without placeholder text right now. I think there's a separate issue for placeholder text—with or without YCM—but I am trying to figure out if it's an issue on my end or not.)
Steps to reproduce
- First, use the following
.vimrc
:
call plug#begin('~/.vim/plugged')
Plug 'ycm-core/YouCompleteMe', { 'do': './install.py' }
Plug 'SirVer/ultisnips'
call plug#end()
- Then use the following snippet:
snippet example "bad example" A
word $0
word $0 again
endsnippet
- Now just type
example
on a vim file, and you should get the result
example$0
word example$0 again
Of course, the $0
doesn't show up, I just left them here to indicate where things will be when you type them)
- Operating System: Mac OS 11.1
- Vim Version: VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Dec 31 2020 06:25:27) macOS version - x86_64
- UltiSnips Version: 66d81fc2c0bda30be69fffa46da0932ee8d5ddd5
- Python inside Vim: 3.9.1
- Docker repo/vimrc: I am sort of new here and could not figure out how to update Vim to version 8.1 in the Docker container, which meant I couldn't use YouCompleteMe. But I have explained the minimal vimrc above, which will hopefully work work. Sorry for the inconvenience!
I am not sure why I didn't see this earlier, but https://github.com/SirVer/ultisnips/issues/1234 seems to be talking about the same thing (but only for curly braces).
Also, probably related: if the auto-expand snippet has ${VISUAL:default text}
inside, the selection and expansion is incorrect (it seems it is combined with the snippet identifier that triggered expansion). This no longer occurs when g:ycm_auto_trigger = 0
.
I think one option to fix this might just be to change ycm_min_chars_for_completion to be large-ish (like 4 or 5), and then only use automatic triggers for short things
Interesting suggestion. This might work for my daily use indeed. Thanks for the tip!
I have pretty much the same thing happening. my snippet:
snippet enum "Enumerate" bA
\begin{enumerate}
\item $0
\end{enumerate}
endsnippet
always results in
\begin{enumerate}
enum$0
\end{enumerate}
when typing enum