Youcompleteme: Ultisnips and completion

Created on 6 Mar 2016  路  9Comments  路  Source: ycm-core/YouCompleteMe

Issue Prelude

Please complete these steps and check these boxes (by putting an x inside
the brackets) _before_ filing your issue:

  • [x] I have read and understood YCM's [CONTRIBUTING][cont] document.
  • [x] I have read and understood YCM's [CODE_OF_CONDUCT][code] document.
  • [x] I have read and understood YCM's [README][readme], especially the
    [Frequently Asked Questions][faq] section.
  • [x] I have searched YCM's issue tracker to find issues similar to the one I'm
    about to report and couldn't find an answer to my problem. ([Example Google
    search.][search])
  • [x] If filing a bug report, I have included the output of vim --version.
  • [x] If filing a bug report, I have included the output of :YcmDebugInfo.
  • [x] If filing a bug report, I have included the output of
    :YcmToggleLogs stderr.
  • [x] If filing a bug report, I have included which OS (including specific OS
    version) I am using.
  • [x] If filing a bug report, I have included a minimal test case that reproduces
    my issue.
  • [x] I understand this is an open-source project staffed by volunteers and
    that any help I receive is a selfless, heartfelt _gift_ of their free time. I
    know I am not entitled to anything and will be polite and courteous.
  • [x] I understand my issue may be closed if it becomes obvious I didn't
    actually perform all of these steps.

Thank you for adhering to this process! It ensures your issue is resolved
quickly and that neither your nor our time is needlessly wasted.

Issue Details

Hello,

To start with, I know there has been a lot of issues and posts around this subject, but I still can't get it to work. My problem is that I have installed UltiSnips and I am unable to have any completion. Before filling in this issue I did some extensive research about the subject. I found this stackoverflow question. I used the following answer in my init.vim:

" if you use Vundle, load plugins:
Plug 'ervandew/supertab'
Plug 'Valloric/YouCompleteMe'
Plug 'SirVer/ultisnips'

" make YCM compatible with UltiSnips (using supertab)
let g:ycm_key_list_select_completion = ['<C-n>', '<Down>']
let g:ycm_key_list_previous_completion = ['<C-p>', '<Up>']
let g:SuperTabDefaultCompletionType = '<C-n>'

" better key bindings for UltiSnipsExpandTrigger
let g:UltiSnipsExpandTrigger = "<tab>"
let g:UltiSnipsJumpForwardTrigger` = "<tab>"
let g:UltiSnipsJumpBackwardTrigger = "<s-tab>"

Whether I use <tab> or <C-n> nothing happens it only scrolls down through the list. I even tried other keys but nothing happens. Here the plugins I installed:

" file browser
Plug 'scrooloose/nerdtree'
Plug 'jistr/vim-nerdtree-tabs'
Plug 'tpope/vim-surround'
Plug 'octol/vim-cpp-enhanced-highlight'
Plug 'ctrlpvim/ctrlp.vim'

" eyecandy
Plug 'bling/vim-airline'
Plug 'edkolev/tmuxline.vim'
Plug 'vim-airline/vim-airline-themes'

" code
Plug 'scrooloose/syntastic'
Plug 'Valloric/YouCompleteMe'
Plug 'DoxygenToolkit.vim'
Plug 'Raimondi/delimitMate'
Plug 'Chiel92/vim-autoformat'
Plug 'godlygeek/tabular'
Plug 'Yggdroot/indentLine'

" snippets
Plug 'SirVer/ultisnips'

" session
Plug 'xolox/vim-session'
Plug 'xolox/vim-misc'
Plug 'ervandew/supertab'

" color syntax
Plug 'morhetz/gruvbox'

Here are the other options of YouCompleteMe:

" java completion
set omnifunc=syntaxcomplete#Complete
let g:EclimCompletionMethod='omnifunc'

" ycm options
let g:ycm_show_diagnostics_ui = 0
let g:ycm_auto_trigger = 1
let g:ycm_add_preview_to_completeopt = 0
let g:ycm_autoclose_preview_window_after_completion = 1
let g:ycm_autoclose_preview_window_after_insertion = 1
let g:ycm_confirm_extra_conf = 0
let g:ycm_min_num_of_chars_for_completion = 2
let g:ycm_filetype_specific_completion_to_disable = {
            \ 'gitcommit': 1,
            \ 'swap': 1
            \ }

" disable for tex files
let g:ycm_filetype_blacklist = {
            \ 'tex' : 1,
            \ 'plaintex' : 1
            \}
let g:ycm_python_binary_path = '/usr/bin/python3'

I am using neovim with neovim --version printing:

NVIM v0.1.3-146-g44024f2
Build type: Dev
Compilation: /usr/bin/cc -march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -Wconversion -Og -g -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wvla -fstack-protector-strong -fdiagnostics-color=auto -DINCLUDE_GENERATED_DECLARATIONS -DHAVE_CONFIG_H -D_GNU_SOURCE -I/tmp/yaourt-tmp-scriptor/aur-neovim-git/src/neovim-git/build/config -I/tmp/yaourt-tmp-scriptor/aur-neovim-git/src/neovim-git/src -I/usr/include -I/usr/include -I/usr/include/luajit-2.0 -I/usr/include -I/usr/include -I/usr/include -I/usr/include -I/usr/include -I/tmp/yaourt-tmp-scriptor/aur-neovim-git/src/neovim-git/build/src/nvim/auto -I/tmp/yaourt-tmp-scriptor/aur-neovim-git/src/neovim-git/build/include

Optional features included (+) or not (-): +acl   +iconv    +jemalloc 
For differences from Vim, see :help vim-differences

         fichier vimrc syst猫me : "$VIM/sysinit.vim"
               $VIM par d茅faut : "/usr/share/nvim"

I am using Archlinux, and installed neovim-git, python-neovim-git and python2-neovim-git packages.

:YcmDebugInfo output :

Printing YouCompleteMe debug information...
-- Server has Clang support compiled in: True
-- Clang version: clang version 3.7.1 (tags/RELEASE_371/final)
-- Server running at: http://127.0.0.1:57975
-- Server process ID: 7977
-- Server logfiles:
--   /tmp/ycm_temp/server_57975_stdout.log
--   /tmp/ycm_temp/server_57975_stderr.log

Thank you very much for all your help :)

Most helpful comment

What makes you think this is a bug in YCM? Literally thousands of users (including myself) use UltiSnips with YCM daily.

Perhaps the problem is that their default configurations conflict and there are just a bunch of options how you go about integrating them. It seems people want to use the <tab> key in different ways. There are roughly 3 approaches I've seen commonly suggested:

  • Use supertab and some UltiSnips scripting
  • Use UltiSnips scripting
  • Just change the expand key for UltiSnips

Personally, I use the third one, as it is by far the simplest. All I have in my .vimrc is this:

" UltiSnips triggering
let g:UltiSnipsExpandTrigger = '<C-j>'
let g:UltiSnipsJumpForwardTrigger = '<C-j>'
let g:UltiSnipsJumpBackwardTrigger = '<C-k>'

That is when I highlight a snippet in YCM's completion menu (or just type one), I hit <CTRL-j> to trigger it and <CTRL-j>/<CTRL-k> to jump around.

Note however, that if you have preview in your completeopt, this can make UltiSnips lose your place, so either remove it or do what I did which is to hack UltiSnips to remove preview from completeopt during snippet editing. The former is easier of course.

I don't think this is a bug in YCM, so I'm going to close this, but if you can get a _reduced_ test case and _steps to reproduce_ including _expected behaviour_ and _actual observed behaviour_ that indicates there's a problem with YCM (and not your configuration, or some other plugin like supertab), then I'd be happy to re-open it ;)

PS

I don't know if this is anything to do with your problem, but there seems to be a stray backtick in your config at the end of g:UltiSnipsJumpForwardTrigger:

let g:UltiSnipsJumpForwardTrigger` = "<tab>"

Might just be a typo in the issue though.

All 9 comments

What makes you think this is a bug in YCM? Literally thousands of users (including myself) use UltiSnips with YCM daily.

Perhaps the problem is that their default configurations conflict and there are just a bunch of options how you go about integrating them. It seems people want to use the <tab> key in different ways. There are roughly 3 approaches I've seen commonly suggested:

  • Use supertab and some UltiSnips scripting
  • Use UltiSnips scripting
  • Just change the expand key for UltiSnips

Personally, I use the third one, as it is by far the simplest. All I have in my .vimrc is this:

" UltiSnips triggering
let g:UltiSnipsExpandTrigger = '<C-j>'
let g:UltiSnipsJumpForwardTrigger = '<C-j>'
let g:UltiSnipsJumpBackwardTrigger = '<C-k>'

That is when I highlight a snippet in YCM's completion menu (or just type one), I hit <CTRL-j> to trigger it and <CTRL-j>/<CTRL-k> to jump around.

Note however, that if you have preview in your completeopt, this can make UltiSnips lose your place, so either remove it or do what I did which is to hack UltiSnips to remove preview from completeopt during snippet editing. The former is easier of course.

I don't think this is a bug in YCM, so I'm going to close this, but if you can get a _reduced_ test case and _steps to reproduce_ including _expected behaviour_ and _actual observed behaviour_ that indicates there's a problem with YCM (and not your configuration, or some other plugin like supertab), then I'd be happy to re-open it ;)

PS

I don't know if this is anything to do with your problem, but there seems to be a stray backtick in your config at the end of g:UltiSnipsJumpForwardTrigger:

let g:UltiSnipsJumpForwardTrigger` = "<tab>"

Might just be a typo in the issue though.

Hello,

Thank you very much for your long and precise answer. So, this time I tested the <tab> key to confirm the choice of the completion menu. Unfortunately it doesn't select it, it just circles through the completion menu.

Here is what I did:
1 - Install vim (I thought that if it worked in vim, it may come from a neovim bug)
2 - Create the most minimal vimrc :

filetype off

call plugin#begin('~/.config/vim/plugged') " just so you know this directory only contains the youcompleteme plugin

Plug 'Valloric/YouCompleteMe'

call plug#end()

3 - Download plugin through vim-plug and compile it
4 - Open a simple file from one of my projects (the ycm_extra_conf.py was already created and never posed me any problem)
5 - Try completion
6 - The completion works with no problem (with and without Ctrl-Space)
7 - Tap <tab> to confirm choice => it cycles through the choices

So what am I doing wrong ?

Thank you very much again for all your help :)

I see. <tab> in YCM does not "select" the completion, it cycles. That's intentional. You don't _need_ to confirm a completion selection in Vim, it does it just by highlighting the selection in the pop-up menu. Notice that it inserts the text of the selected item automatically?

Anyway, if you feel strongly the need to select an item and dismiss the pop-up menu, then you can hit <Ctrl-Y>.

Please see :help ins-completion for the details.

By default, YCM maps <tab> to effectively <c-n> when in popup menu mode. See the docs for details on how to change the "next completion" and "previous completion" mappings.

Hello,

Thank you again for your quick and very precise answer.

So, I now feel a bit stupid, I am really sorry :/

I'm really sorry but I just have one last question: is it possible to have also the completion of the function arguments ?

For example if I type:

memcpy

it could be completed by:

memcpy(void *dest, const void *src, size_t n);

Thank you very much in advance :) and really sorry for the bather :/

Thank you again for all your time and patience :)

[EDIT]

Sorry, I've made some research and I just saw that this wasn't implemented yet #1300.

Thank you very much again :)

[/EDIT]

Hello @puremourning,
I read your comment and you mentioned that you have hacked Ultisnips to not loose its place while YCM opens the preview window. Would you share this information please. I'm really interested in this method as it is the only problem i have while using Ultisnips together with YCM.
Best regards,
Fabian

@vodan Yeah, I'd like to see this too. I'm having problems with that.

This is the diff vs the version of UltiSnips I use. YMMV, this is not a proper patch/PR whatever. It's just what I use.

diff --git a/autoload/UltiSnips/map_keys.vim b/autoload/UltiSnips/map_keys.vim
index 218b507..9663b62 100644
--- a/autoload/UltiSnips/map_keys.vim
+++ b/autoload/UltiSnips/map_keys.vim
@@ -53,6 +53,10 @@ if !exists("g:UltiSnipsEnableSnipMate")
     let g:UltiSnipsEnableSnipMate = 1
 endif

+if !exists("g:UltiSnipsDisablePreviewWindowInSnips")
+    let g:UltiSnipsDisablePreviewWindowInSnips = 0
+endif
+
 function! UltiSnips#map_keys#MapKeys()
     if g:UltiSnipsExpandTrigger == g:UltiSnipsJumpForwardTrigger
         exec "inoremap <silent> " . g:UltiSnipsExpandTrigger . " <C-R>=UltiSnips#ExpandSnippetOrJump()<cr>"
diff --git a/doc/UltiSnips.txt b/doc/UltiSnips.txt
index 13b6baf..7663eb4 100644
--- a/doc/UltiSnips.txt
+++ b/doc/UltiSnips.txt
@@ -219,6 +219,16 @@ g:UltiSnipsEnableSnipMate
                             SnipMate snippets. Defaults to "1", so UltiSnips
                             will look for SnipMate snippets.

+                                                        *g:UltiSnipsDisablePreviewWindowInSnips*
+g:DisablePreviewWindowInSnips
+                            When a snip is active (i.e. we are editing the
+                            tabs and replacements), disable the preview
+                            window when this option is set to 1. Technically,
+                            this removes |preview| from |completeopt|.
+                            Enabling this setting prevents the snip becoming 
+                            inactive when using omnicomplete or other 
+                            completion engines which show the preview 
+                            window while editing a snip. Defaults to "0".

                                                        *:UltiSnipsAddFiletypes*
 The UltiSnipsAddFiletypes command allows for explicit merging of other snippet
diff --git a/pythonx/UltiSnips/snippet_manager.py b/pythonx/UltiSnips/snippet_manager.py
index 331500e..73eff1e 100644
--- a/pythonx/UltiSnips/snippet_manager.py
+++ b/pythonx/UltiSnips/snippet_manager.py
@@ -357,6 +357,12 @@ class SnippetManager(object):
         _vim.command('snoremap <buffer> <silent> ' + self.backward_trigger +
                      ' <Esc>:call UltiSnips#JumpBackwards()<cr>')

+        if _vim.eval('g:UltiSnipsDisablePreviewWindowInSnips') == '1':
+            # backup completeopt
+            _vim.command('let g:ultisnips_completopt_old = &completeopt')
+            # and remove the preview option
+            _vim.command('set completeopt-=preview')
+
         # Setup the autogroups.
         _vim.command('augroup UltiSnips')
         _vim.command('autocmd!')
@@ -395,6 +401,11 @@ class SnippetManager(object):
             _vim.command('autocmd!')
             _vim.command('augroup END')
             self._inner_state_up = False
+
+            if _vim.eval('g:UltiSnipsDisablePreviewWindowInSnips') == '1':
+                # restore completeopt
+                _vim.command('set completeopt = g:ultisnips_completopt_old')
+
         except _vim.error:
             # This happens when a preview window was opened. This issues
             # CursorMoved, but not BufLeave. We have no way to unmap, until we

@puremourning How do I use that to edit my map_keys.vim? I don't know the diff file format.

Just manually apply the changes. This is YMMV stuff (sorry i'm not about to go to a lot of effort on this one).

If you can't work it out I would recommend reporting the issue upstream to UltiSnips and see if they will do something similar (the preview window cursor jump causes ultisnips to think the user moved outside of the snippet range).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pprzetacznik picture pprzetacznik  路  4Comments

ioeric picture ioeric  路  4Comments

blackode picture blackode  路  3Comments

beojan picture beojan  路  4Comments

samfux84 picture samfux84  路  3Comments