-
Notifications
You must be signed in to change notification settings - Fork 19
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
On automatic triggering of relevant completion suggestions via snippets #204
Comments
I'll try to reproduce it. If you press Tab after the snippet is expanded, is any completion offered? |
With just the bare minimum So, Tab after I should add that the suggestions that come from Ctrl-n and Ctrl-p are forward looking and backward looking plain textual completions (one could get this completion without VimTeX for instance) and not omnifunc completions (which is due to VimTeX's interaction with MuComplete). With CtrlX-CtrlO, I get the actual omnifunc completions which is what I was hoping gets automatically triggered from within the snippet placeholder position. |
Thanks for the feeback. In principle, something like this should work: fun MyTabAction()
return "\<c-r>=UltiSnips#ExpandSnippet()\<cr>\<plug>(MyFwd)"
endf
let g:UltiSnipsExpandTrigger = "<f5>" " Not to interfere with the mapping below
imap <plug>(MyFwd) <plug>(MUcompleteFwd)
imap <expr> <silent> <tab> MyTabAction() This does perform completion, but unfortunately the pop-up menu does not stay open. I have not found a way to prevent that, and I have not understood why that happens. My suggestion would be to follow the recommendations in MUcomplete's help:
By doing so, MUcomplete will offer to complete snippets' names and you can expand them by selecting them from the pop-up menu and pressing Enter. After that, you may press Tab to complete the inserted entry. This (Enter + Tab) is still one keystroke more than what you want to achieve; on the other hand, you may save several keystrokes by enabling |
To be clear, the problem with the pop-up menu closing after expanding the snippet is not related to MUcomplete. The same happens if you try to complete with Ctrl-X Ctrl-N after the expansion: fun MyTabAction()
let l:expand_snippet = "\<c-r>=UltiSnips#ExpandSnippet()\<cr>"
let l:complete = "\<c-x>\<c-n>\<c-n>" " Ctrl-x Ctrl-n for keyword completion, Ctrl-n to select an entry (assumes completeopt contains noselect)
return l:expand_snippet .. l:complete
endf
let g:UltiSnipsExpandTrigger = "<f5>" " Not to interfere with the mapping below
imap <expr> <silent> <tab> MyTabAction() Maybe UltiSnips's developers have an idea on how to make Ctrl-X Ctrl-N work. If so, it's likely that MUcomplete can be made to work in the same way. |
This works at my end. Thank you for your help. |
fun MyTabAction()
return "\<c-r>=UltiSnips#ExpandSnippet()\<cr>\<plug>(MyFwd)"
endf
let g:UltiSnipsExpandTrigger = "<f5>" " Not to interfere with the mapping below
imap <plug>(MyFwd) <plug>(MUcompleteFwd)
imap <expr> <silent> <tab> MyTabAction() and fun MyTabAction()
let l:expand_snippet = "\<c-r>=UltiSnips#ExpandSnippet()\<cr>"
let l:complete = "\<c-x>\<c-n>\<c-n>" " Ctrl-x Ctrl-n for keyword completion, Ctrl-n to select an entry (assumes completeopt contains noselect)
return l:expand_snippet .. l:complete
endf
let g:UltiSnipsExpandTrigger = "<f5>" " Not to interfere with the mapping below
imap <expr> <silent> <tab> MyTabAction() If it is not asking too much, could you please provide a high level explanation of what precisely is being done in these functions and why they work while it would not work before? In particular, the lines: imap <plug>(MyFwd) <plug>(MUcompleteFwd)
imap <expr> <silent> <tab> MyTabAction()
return "\<c-r>=UltiSnips#ExpandSnippet()\<cr>\<plug>(MyFwd)"
let l:expand_snippet = "\<c-r>=UltiSnips#ExpandSnippet()\<cr>"
let l:complete = "\<c-x>\<c-n>\<c-n>" " Ctrl-x Ctrl-n for keyword completion, Ctrl-n to select an entry (assumes completeopt contains noselect)
return l:expand_snippet .. l:complete |
We first set the keystroke to activate UltiSnips to be something different from Tab. This is because we want to define Tab ourselves (I have chosen let g:UltiSnipsExpandTrigger = "<f5>" Then we define an internal mapping (see imap <plug>(MyFwd) <plug>(MUcompleteFwd) We are now free to map Tab to whatever we want, and we choose to map it to an expression ( imap <expr> <silent> <tab> MyTabAction() The expression that is evaluated is the string returned by The second part of the string just triggers our mapping, which invokes MUcomplete. In the second example, I have split the string just for clarity, assigning each part to a local variable. Then, the In the second example, the second part of the string is used to trigger keyword completion (Ctrl-X Ctrl-N) and to select the first item in the pop-up menu (another Ctrl-N). Note that, when such strings are evaluated in a mapping Hope this helps! |
I use
mucomplete
in conjunction withUltiSnips
andVimTeX
for autocompletion of.tex
files. What I would like to have is automatically triggering of completion suggestions based on context of a snippet placeholder's cursor position. An example follows:I have the following
.vimrc
Consider the following
.tex
file:I have the following snippets via UltiSnips:
On typing
refe<SnippetTrigger>
, one should get:(\ref{eq:|})
where|
denotes the cursor in insert mode. I was hoping that when this happens, automatically, all of the equationlabels
of the.tex
file whose labels start witheq:
are displayed in a popup for automatic completion. (Note, this is after ensuring that the.aux
file resides in the folder following one compilation as answered here)However, this does not happen. The automatic triggering happens only if the user manually types in
\ref{|
individually that the triggering happens.Please see explanatory video/gif of the above at : https://imgur.com/a/3attCKA
Is this expected behavior or is there a setting to have automatic completion suggestions triggered even if the cursor is at a placeholder position within a snippet?
Thank you.
PS: The official response from VimTeX seems to be that it is not possible from within VimTeX to trigger such snippet placeholder contextual completion. See here
The text was updated successfully, but these errors were encountered: