Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

SnipMate/UltiSnips integration #36

Closed
kballenegger opened this Issue · 87 comments
@kballenegger

A killer feature would be for YCM to include SnipMate snippets in its suggestions.

I'm making this an issue in case a contributor sees this. I unfortunately do not have the skills required to build this.

@Valloric
Owner

I'm not a fan of this. I use snippets as well (UltiSnips) but I don't think integrating it with a code-completion system would be the best approach.

Thanks for the feedback though!

@Valloric Valloric closed this
@capitalist

For what it's worth. I think snippet integration would be nice as well. My snippets no longer complete with YCM, so I may have explore changing the trigger.

@kballenegger

Ditto, see how Xcode does it. It's really nice, your snippets are offered as autocompletion, it's super neat.

@drasill

+1 (ultisnips)

"snippets offered as autocompletion" is something I didn't imagine, it could be awesome.

@drasill

Although, binding <C-j> to ultisnips make it easy to use again.

@Valloric
Owner

I'm slowly changing my mind about this. If we could figure out a way for YCM to talk to UltiSnips/Snipmate in a way that doesn't complicate matters too much, I'd support it.

UltiSnips support will probably come first; I'm not sure about Snipmate because upstream has a note about Snipmate dying and it recommends UltiSnips, so that's not a good sign.

@Valloric Valloric reopened this
@Townk

The way clang_complete uses Ultisnips is the best approach. Besides allow you to complete snippets with once you accepted a completion and this completion is a function call, than YCM should provide an "anonymous" snippet with the parameters of the function to be completed. Ex:

I type:

prtf

Than YCM offers me "printf" among others. After I press than , YMC shuld give me this:

printf("format string", parameters);

Where:

"format string" - is the first argument of the snippet
, parameters - is the optional argument

Also, regarding how to complete a snippets or "other completions", I think YMC should do this:

I type:

if

YMC provides me some options. The snippets should be listed on top of the options and marked somehow so user can clearly see what's this about. If user, press , than Ultisnips should be triggered and if the offered snippet has more than one possibility, than YCM should change the completion list to show all snippets available for the chosen snippet.

I'm pretty sure if you contact the developers of Ultisnips they can help you figure out a way to implement that.

@Valloric
Owner

I'll probably talk to the UltiSnips developer at some point, yes.

I like your first feature, where pressing TAB after "ptrf" also inserts the parameter names. But this can be implemented without UltiSnips actually.

The second feature sound good too, but that will not be easy to implement and will require quite a bit of cooperation with the snippets plugin.

@capitalist

Wow, how often does a maintainer remain open-minded after dismissing an issue.

Loving YCM and now @Valloric too. Respect.

@Townk

Agree that "parameter" completion can be achieved without Ultisnips. That being said, Ultisnips already provide a python API to do that, and it'll give you the possibility to use powerful snippets features like python interpolation.

@Valloric
Owner

@Townk I didn't know UltiSnips provided such an API. I'll be using it then.

@sotte

This is the active clone of snipmate which is used quite a lot: https://github.com/garbas/vim-snipmate

@Valloric
Owner

@sotte From the top of the README in that branch:

See snipmate-snippets readme about how to configure and use Ultisnips as alternative That branch also supports completion menu now Thus there is only one reason left to keep using snipmate from my point of view: not having python support. In other words: upstream of snipmate is almost dead.

Also see the issue linked from the first line in the README. This is written by the maintainers of the snipmate clone. Here's an excerpt:

Dear fellow snipmate community. It was a great honor working for you. [...] However for quite a long time snipmate has been broken in various ways - and me and Rok wonder whether its worth fixing snipmate - cause there are other snippet engines for Vim which are more powerful and which do just work - such as ultisnips or xptemplate.

I think this means that SnipMate is dead, or very close to it.

@Townk

@sotte another thing is that Ultisnips kind provide some snipmate compatibility. It defines the "Filename" function and the g:snips_author variable that are used by some snippets. It also provides a script called "convert_snipmate_snippets.py", I believe you can just convert your snippets and start using Ultisnips. Give it a try!

@pvinis

until ultisnips support comes, how can i make to trigger ycm completion, and to trigger ultisnips completion? do you all use another key for ultisnips? i saw on valloric's vimrc a meta key combination, but can't seem to be able to use meta on macvim..

@xgalaxy

In your vimrc you have to :set macmeta for the options key to work correctly.
If your using macvim in terminal, it wont work regardless.

@mindfulmonk

Can someone give me their config with working keybindings? Can't get UltiSnips to work in terminal.

@bmedicke

Mapping UltiSnips to ctrl-j/k works fine for me.

let g:UltiSnipsExpandTrigger="<c-j>"
let g:UltiSnipsJumpForwardTrigger="<c-j>"
let g:UltiSnipsJumpBackwardTrigger="<c-k>"

See :h UltiSnips-triggers.

That said I like the idea of it being more integrated with YCM.

@jbeja

Thanks @bmedicke, works like a charm

@UncleBill

+1 for UltiSnips. It is awesome!

@AllisonV

+1

@johntyree

Neocomplcache also has a feature like this, although it basically reimplemented the snippets engine.

That said, it's a great feature for the same reasons as identifier autocompletion, namely you don't want to have your entire snippet collection in your head at all times. Almost all of the snippets I use I discovered because neocomplcache popped them up as I was typing.

As a final point, I don't know if this still "under vote" or something, but having an endless chain of "+1" and :+1: is pretty terrible for everyone else that has commented in this thread. Please don't.

@dbrgn

In the meantime you should mention the g:snips_trigger_key option (and the UltraSnips equivalent) in your FAQ.

@JazzCore

I've managed to get this working, you can check this branch. If you wish to try it, you will need a quite recent version of UltiSnips. I will not make a pull request for this because it's mainly a hack to add general completers and I agree with @Valloric that this is not so useful. Maybe someday @Valloric or I will make a nice implementation for general completers and there will be a better implementation.

For correct completion and snippet expanding with a TAB key you can use this function:

" UltiSnips completion function that tries to expand a snippet. If there's no
" snippet for expanding, it checks for completion window and if it's
" shown, selects first element. If there's no completion window it tries to
" jump to next placeholder. If there's no placeholder it just returns TAB key 
function! g:UltiSnips_Complete()
    call UltiSnips_ExpandSnippet()
    if g:ulti_expand_res == 0
        if pumvisible()
            return "\<C-n>"
        else
            call UltiSnips_JumpForwards()
            if g:ulti_jump_forwards_res == 0
               return "\<TAB>"
            endif
        endif
    endif
    return ""
endfunction

Due to fact that YCM maps its keys in autoload script after all plugins, mapping in .vimrc will not help. So, you need to map it manually or some other way. I've used this mapping:

exec "inoremap <silent> " . g:UltiSnipsExpandTrigger . " <C-R>=g:UltiSnips_Complete()<cr>"
@johntyree

Due to fact that YCM maps its keys in autoload script after all plugins, mapping in .vimrc will not help. So, you need to map it manually or some other way.

This is probably the single most annoying thing about Vim plugins. Especially "revolutionary" ones. If I want to steamroll all of my key maps, I'll do so. Please don't do it for me. Some of us use more than one plugin at a time and this kind of thing breaks them in unexpected, unpredictable ways with no hope of debugging.

@Valloric
Owner

@johntyree YCM provides options for changing pretty much all of the default mappings. There have to be some defaults set because the defaults work for most people. Nobody wants to install a plugin and then create 10 different mappings just to be able to use it. They should all me remappable, sure, but every plugin should come with defaults.

@dbrgn

I just took a look at the UltiSnips screencasts. This definitely needs to be integrated with YCM! Awesome stuff.

@mikebobroski

@JazzCore, thanks for the UltiSnips completion function posted above.

I was able to add the mapping to .vimrc by calling it on BufEnter. Here's the line:

au BufEnter * exec "inoremap <silent> " . g:UltiSnipsExpandTrigger . " <C-R>=g:UltiSnips_Complete()<cr>"
@sethfowler

@JazzCore, thanks for working on this. I felt like I got the most benefit out of simply having the snippets listed in the completion list. The overloaded functionality for the tab key was somewhat problematic, though. What happened for me was that as soon as a snippet got expanded, the YCM completion menu disappeared and selecting the fields of the snippet took priority. This flow doesn't seem right to me, as it means that you can't easily tab past a snippet to access another completion. I'd prefer if the expanded snippet only served as a preview of sorts until I took some action to confirm that I wanted that snippet. (Maybe hitting the Enter key?)

If I get some time in the next couple of weeks I may take a look at what it would take to integrate this more cleanly.

@johntyree

I had the same issue with <Tab> as a super catch-all key in SPF13.

I'm using <C-K> for snippet expansion in neocomplcache+neosnippets and I'm very happy with it.

@Valloric Valloric closed this issue from a commit
@Valloric Rewriting the code from the pull request
This implements the filename completer and introduces integration with
UltiSnips. The user will now see snippets in the completion menu. After
selecting a snippet, the user should invoke the UltiSnips trigger key
(which should be changed from the default of TAB) to trigger the snippet
expansion.

Fixes #77, Fixes #36
aa9127e
@Valloric Valloric closed this in aa9127e
@capitalist

Ok, this feature works really well and is a pleasure to use.

@mindfulmonk
let g:UltiSnipsExpandTrigger = '<c-l>'
let g:UltiSnipsJumpForwardTrigger = '<c-j>'
let g:UltiSnipsJumpBackwardTrigger = '<c-k>'
let g:UltiSnipsListSnippets = '<c-m>'

It would be great to be able to use TAB instead of a different mapping

@JazzCore

take a look at function I've posted above. It will work, but with some limitations

@mindfulmonk

@JazzCore Got it working by putting your function into vimrc + @mikewho mapping. Cheers :)

@Valloric
Owner

I'll probably be adding something like what @JazzCore added above to YCM.

@jcostello

The integration isnt working for me. YCM didnt show the list of snippets that ultisnip provides me. Any sugestion?

@JazzCore

Please elaborate. Try opening a python file and write de. Does it list any snippets ( like desc or defn) in completions? If not, try running :py print UltiSnips_Manager in command mode.

@jcostello

de doesnt bring me any snippet. :py print UltiSnips_Manager prints the object
<UltiSnips.SnippetManager object at 0x7fc37514d390>

Did i have to configure something in the .vimrc?

PD: I installed Ultisnips and YCM with Vundler

" YouCompleteMe
Bundle 'Valloric/YouCompleteMe'
" Ultisnips
Bundle 'SirVer/ultisnips'  
@JazzCore

No, you dont need to configure anything. I dont really know whats wrong, all should run fine with this settings. Try opening a python file and run :py print UltiSnips_Manager._snips( '', 1 ).

To clarify this, take a look at gif here: #257. You should get something like this ( lines with <snip> are snippets ).

@jcostello

Yeah, i saw that yesterday but i dont get any snippet completion.
When i run :py print UltiSnips_Manager._snips( '', 1 ). i get:

[Snippet(box,"A nice box with the current comment symbol",b), Snippet(bbox,"A nice box over the full width",b), Snippet(lorem,"Lorem Ipsum - 50
 Words",b)]

Ultsnips clearly is working correctly. Maybe is something in my .vimrc

colorscheme molokai
syntax on

  filetype plugin on

  autocmd FileType python set omnifunc=pythoncomplete#Complete
  autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS
  autocmd FileType html set omnifunc=htmlcomplete#CompleteTags
  autocmd FileType css set omnifunc=csscomplete#CompleteCSS
  autocmd FileType xml set omnifunc=xmlcomplete#CompleteTags
  autocmd FileType php set omnifunc=phpcomplete#CompletePHP
  autocmd FileType c set omnifunc=ccomplete#Complete
  autocmd FileType ruby,eruby set omnifunc=rubycomplete#Complete
  autocmd FileType ruby,eruby let g:rubycomplete_buffer_loading = 1
  autocmd FileType ruby,eruby let g:rubycomplete_rails = 1
  autocmd FileType ruby,eruby let g:rubycomplete_classes_in_global = 1

" Basics {
  set nocompatible        " must be first line

  set modelines=0
  set tabstop=2
  set shiftwidth=2
  set softtabstop=2
  set smarttab      " insert tabs on the start of a line according to shiftwidth, not tabstop
  set expandtab
  set encoding=utf-8
  set scrolloff=3
  set autoindent    " always set autoindenting on
  set copyindent    " copy the previous indentation on autoindenting
  set showmode
  set showcmd
  set hidden
  set wildmenu
  set wildmode=list:longest,full
  set completeopt=menu,menuone,longest
  set cursorline
  set ttyfast
  set ruler
  set backspace=indent,eol,start
  set laststatus=2
  set relativenumber
  set undofile
  set history=1000         " remember more commands and search history
  set undolevels=1000      " use many muchos levels of undo
" }

" Paste {
  if has ('x') && has ('gui') " on Linux use + register for copy-paste
      set clipboard=unnamedplus
  elseif has ('gui') " one mac and windows, use * register for copy-paste
      set clipboard=unnamed
  endif

  set pastetoggle=<F2>
" }

" Search {
  set ignorecase
  set smartcase
  set gdefault
  set incsearch
  set hlsearch
  set showmatch
  nnoremap <leader><space> :noh<cr>
  nnoremap <tab> %
  vnoremap <tab> %
  nnoremap / /\v
  vnoremap / /\v
" }

" Mappings {
  let mapleader = ","

  nnoremap <up> <nop>
  nnoremap <down> <nop>
  nnoremap <left> <nop>
  nnoremap <right> <nop>
  inoremap <up> <nop>
  inoremap <down> <nop>
  inoremap <left> <nop>
  inoremap <right> <nop>
  nnoremap j gj
  nnoremap k gk
  nnoremap ; :
  au FocusLost * :wa

  nnoremap <leader>w <C-w>v<C-w>l
  nnoremap <leader>q <C-w>q
  " Quickly edit/reload the vimrc file
  nmap <silent> <leader>vo :e $MYVIMRC<CR>
  nmap <silent> <leader>vl :so $MYVIMRC<CR>

  nnoremap <C-h> <C-w>h
  nnoremap <C-j> <C-w>j
  nnoremap <C-k> <C-w>k
  nnoremap <C-l> <C-w>l
" }

" Setting up the directories {
    set nobackup
    set noswapfile
    if has('persistent_undo')
      set undofile                "so is persistent undo ...
      set undodir=~/.vim/.undo
      set undolevels=1000         "maximum number of changes that can be undone
      set undoreload=10000        "maximum number lines to save for undo on a buffer reload
    endif
" }

" Vundle

  "filetype off

  set rtp+=~/.vim/bundle/vundle/
  call vundle#rc() " let Vundle manage Vundle

  " required
  Bundle 'gmarik/vundle' 

  " Command-T
  Bundle 'Command-T'                
  " Ack
  Bundle 'ack.vim'                  
  " YouCompleteMe
  Bundle 'Valloric/YouCompleteMe'
  " Ultisnips
  Bundle 'SirVer/ultisnips'         
  " Syntastic
  Bundle 'scrooloose/syntastic'
  " EasyTags
  Bundle 'xolox/vim-easytags'

  filetype plugin indent on

" END VUNDLE

" Plugins {

  " Ack {
    let g:ackprg="ack-grep -H --nocolor --nogroup --column"
  " }

  " Snippets {
   " let g:UltiSnipsExpandTrigger="<tab>"
   " let g:UltiSnipsJumpForwardTrigger="<tab>"
   " let g:UltiSnipsListSnippets="<c-e>"
  " }
  " Syntastic
    let g:syntastic_error_symbol='✗'
    let g:syntastic_warning_symbol='⚠'
    let g:syntastic_enable_highlighting=0
    let g:syntastic_auto_loc_list=1

  " EasyTags
    set tags=./tags;

    let g:easytags_always_enabled = 1
    let g:easytags_file = './tags'
    let g:easytags_dynamic_files = 1
    let g:easytags_auto_highlight = 1
    let g:easytags_updatetime_min = 5000

  " You Complete Me
    let g:ycm_global_ycm_extra_conf = '~/.vim/.ycm_extra_conf.py'
    let g:ycm_allow_changing_updatetime = 0
    let g:ycm_complete_in_comments = 1
    au BufWritePost *.c,*.cpp,*.h YcmForceCompileAndDiagnostics
    nnoremap <F5> :YcmForceCompileAndDiagnostics<CR>

    if has("autocmd")
      autocmd FileType cpp,c,ruby,python,java let g:easytags_include_members = 1
    endif
@JazzCore

Well, it IS problem in your .vimrc. Bundles must be on top of config and be preceeded with filetype off line. Rewrite it to something like this:

set nocompatible
filetype off " required
" Vundle
set rtp+=~/.vim/bundle/vundle/
call vundle#rc() " let Vundle manage Vundle

" required
Bundle 'gmarik/vundle' 
" Command-T
Bundle 'Command-T'        
" rest of the bundles       
filetype plugin indent on " required

" rest of the config here

I've tested this before and after the change so it should work fine. Most probably the problem here it that YCM tries to load UltiSnips python module before ultisnips is actually initialized.

@jcostello

Thank you very much. That solves the problem. :+1: :tada:

@JazzCore

Good, glad to help.

@mgutz

@Valloric, @JazzCore you guys rock!

YCM + UltiSnips = Ultimate Editor

@jbeja

@mgutz I think that VIM was already the Ultimate Editor even without it XD.

@gbataille

arf. I followed what you did JazzCore but I can't get Tab to expand the snippet.
in case somebody can spare a minute:
here is my vimrc (certainly a bit cluttered)
https://gist.github.com/gbataille/5548857

thanks

@mgutz

@gbataille Did you add the autocmd snippet by @mikewho above? That binds it to tab

@gbataille

well unless I misunderstood something, I did yes (look at the last line in the Gist)

@fatih

I have the same problem. I definetly see the snippets:

ultisnip

But what should I do select them? They do not expand. I select multiple times with via tab and also try to select with enter but it doesn't expand. (sidenote: file completer works fine via / and ./)

@fatih

Ok because there seems no single source I've just packed them togheter.

  1. Install YCM
  2. Install UltiSnips

After that it just works, but the keys are kinda different. If you want to expand with tab and jump forward with tab you have to add these additional to your vimrc.

3 . Add function from @JazzCore:

function! g:UltiSnips_Complete()
    call UltiSnips_ExpandSnippet()
    if g:ulti_expand_res == 0
        if pumvisible()
            return "\<C-n>"
        else
            call UltiSnips_JumpForwards()
            if g:ulti_jump_forwards_res == 0
               return "\<TAB>"
            endif
        endif
    endif
    return ""
endfunction

4 . Create a automatic BufEnter for the function above:

au BufEnter * exec "inoremap <silent> " . g:UltiSnipsExpandTrigger . " <C-R>=g:UltiSnips_Complete()<cr>"

5 . Finally define the tab key for expansion:

let g:UltiSnipsExpandTrigger="<tab>"
let g:UltiSnipsJumpForwardTrigger="<tab>"

It seems to work very nicely. I just want to sure if all three steps are necessary? Thanks for this great work.

@JazzCore

@gbataille there is a typo in your config. You have:

 au BufEnter * exec "inoremap <silent> " . g:UltiSnipsExpandTrigger . "<C-R>=g:UltiSnips_Complete()<cr>"

Should be:

 au BufEnter * exec "inoremap <silent> " . g:UltiSnipsExpandTrigger . " <C-R>=g:UltiSnips_Complete()<cr>"

Note the space before <C-R>, its important

@JazzCore

@fatih, you need only g:UltiSnipsJumpForwardTrigger="<tab>", g:UltiSnipsExpandTrigger is set to Tab by default

@gbataille

@JazzCore thanks. I can see now how it was wrong, but it still does not work though :(

I changed it and created a new gist
https://gist.github.com/gbataille/5549590

@JazzCore

@gbataille you are using VERY outdated version of UltiSnips. You should use upstream version. Change Bundle 'vim-scripts/UltiSnips' to Bundle 'SirVer/ultisnips', update and check if it will fix it. By update i mean remove a ultisnips dir from bundle folder and run BundleInstall again

@fatih

@JazzCore thanks a lot. Just merged them into https://github.com/fatih/subvim. Awesome Work!

@JazzCore

@fatih dont forget about an issue about this function: #36 (comment). This can be a stopper for some people. I have a fix for this planned but this will be a ultisnips patch, not YCM.

@gbataille

this is getting frustrating...
thanks @JazzCore. I did not know indeed which repo to use when I found several.
still. Does not work :(
just in case, I have uploaded a new Gist
https://gist.github.com/gbataille/5549742

trying a few things, I tried to comment all the other plugins but to no effect.

would you have an idea how I could debug the situation maybe? I'm quite lost as to how to investigate this.

thanks

@JazzCore

Keep in mind that you set autocmd on BufEnter. So the key will be remapped only when you switch buffer or open new file, not directly after vim startup. Have you switched buffers? If this still does not work, print output of :verbose imap <tab> ( after buffer switch ) and :py print UltiSnips_Manager.

Otherwise, your .vimrc works fine for me.

@gbataille
@jcostello

I tried to snip a "def" but when i was typing the name of the function, it fires another snip, so I change de order of the g:UltiSnips_Complete function to try first a jump forwards intead of a expand. Enjoy

    function! g:UltiSnips_Complete()
      call UltiSnips_JumpForwards()
      if g:ulti_jump_forwards_res == 0
        call UltiSnips_ExpandSnippet()
        if g:ulti_expand_res == 0
          if pumvisible()
            return "\<C-n>"
          else
            return "\<TAB>"
          endif
        endif
      endif
      return ""
    endfunction
@fatih

@JazzCore I'm using this thing in vimrc

" Stop completion with enter, in addition to default ctrl+y
imap <expr> <CR> pumvisible() ? "\<c-y>" : "<Plug>delimitMateCR"

You can stop an auto completion via ctrl+y. This will map it to enter + will not break delimitMate. Therefore it just works like charm.

@zx9597446

hi, there, I still can't get YCM working with Ultisnippets, I use gvim on windows, YCM can list snips, but can't expand it.
I tried two ways:
-------------------------A-------------------------
let g:UltiSnipsExpandTrigger=""
let g:UltiSnipsJumpForwardTrigger=""
let g:UltiSnipsJumpBackwardTrigger=""
------------------------A--------------------------

------------------------B-----------------------------
function! g:UltiSnips_Complete()
call UltiSnips_ExpandSnippet()
if g:ulti_expand_res == 0
if pumvisible()
return "<C-n>"
else
call UltiSnips_JumpForwards()
if g:ulti_jump_forwards_res == 0
return "<TAB>"
endif
endif
endif
return ""
endfunction

BufEnter * exec "inoremap " . g:UltiSnipsExpandTrigger . " =g:UltiSnips_Complete()"

let g:UltiSnipsExpandTrigger=""
let g:UltiSnipsJumpForwardTrigger=""
---------------------------B------------------------------
none of these work, I'm using most recently YCM and Ultisnippets.

here's my _vimrc:

filetype off
filetype plugin indent off
set runtimepath+=$GOROOT/misc/vim
filetype plugin indent on
syntax on

filetype off " required!
set rtp+=~/vimfiles/bundle/vundle/
call vundle#rc()

" let Vundle manage Vundle
" required!
Bundle 'gmarik/vundle'

" My Bundles here:
Bundle 'Valloric/YouCompleteMe'
Bundle 'SirVer/ultisnips'

Bundle 'kien/ctrlp.vim'
Bundle 'scrooloose/syntastic'
filetype plugin indent on " required!

source $VIM_vimrc

set number
set tabstop=4
set shiftwidth=4
set backupdir=$TMP
set noswapfile
set cmdheight=3

set guifont=Courier_New:h12:cANSI
set guioptions-=T
set ic
set nowrapscan
set cursorline
set autochdir

map :cn

map :NERDTreeToggle
map :silent !ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .
map :silent !start cmd.exe .
map :simalt ~x

set tags+=tags;

autocmd BufEnter *.bat map :!cmd /c %
autocmd BufEnter *.js map :!cscript %
autocmd BufEnter *.lua map :!lua %
autocmd BufEnter *.vbs map :!cscript %
autocmd BufEnter *.html map :!cmd /c %
autocmd BufEnter *.htm map :!cmd /c %
autocmd BufEnter *.py map :!python %
autocmd BufEnter *.orbit.lua map :!orbit -p80 %

" Automatically open, but do not go to (if there are errors) the quickfix /
" location list window, or close it when is has become empty.
"
" Note: Must allow nesting of autocmds to enable any customizations for quickfix
" buffers.
" Note: Normally, :cwindow jumps to the quickfix window if the command opens it
" (but not if it's already open). However, as part of the autocmd, this doesn't
" seem to happen.
"autocmd QuickFixCmdPost [^l]* nested cwindow
"autocmd QuickFixCmdPost l* nested lwindow

autocmd BufEnter *.go set makeprg=go\ build
autocmd BufEnter *.go map :!go run %
autocmd BufEnter *.go map :make
autocmd BufEnter *.go set tags+=$GOROOT/tags,$GOPATH/tags
autocmd BufEnter *.go map :!ctags --extra=+q -f \%GOPATH\%\tags -R \%GOPATH\%

autocmd BufWritePre *.go :silent Fmt

color Vc
set autoread

set fileencodings=ucs-bom,utf-8,cp936,gb18030,big5,euc-jp,euc-kr,latin1

let g:UltiSnipsExpandTrigger=""
let g:UltiSnipsJumpForwardTrigger=""
let g:UltiSnipsJumpBackwardTrigger=""

let g:syntastic_auto_jump=1

map zz :w

by use this _vimrc, even can't expand snips

@Chiel92

@zx9597446 Just like suggested earlier in this issue, having ycm and ultisnips installed properly, the following lines in your .vimrc should do the trick:

let g:UltiSnipsExpandTrigger="<c-j>"
let g:UltiSnipsJumpForwardTrigger="<c-j>"
let g:UltiSnipsJumpBackwardTrigger="<c-k>"

No idea if this is what you want, but it is a sane mapping and it works. It says also in the FAQ that you'll have to change the UltiSnips mappings. https://github.com/Valloric/YouCompleteMe#ycm-conflicts-with-ultisnips-tab-key-usage

@brada brada referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
@avoine

I found that using the supertab plugin is also working:

http://stackoverflow.com/a/22253548

@elmart

Hi,

I just wanted to know which is the current status of this:
@fatih Is your summary (#36 (comment)) current / still the last word on this?
@JazzCore What about the UltiSnips patch you mentioned at #36 (comment) ? Still consider doing it? Done?
@Valloric What about adding @JazzCore 's snippet to YCM you mentioned at #36 (comment) ? Still consider doing it? Done?

Thanks, guys. Great work.

@elmart

Ok, I leave here the results of my own investigation:

#36 (comment) is no more current. Two reasons:

  • UltiSnips_JumpForwards and UltiSnips_ExpandSnippet are now called UltiSnips#JumpForwards and UltiSnips#ExpandSnippet.
  • Even if you correct that, it still doesn't work, cause the autocommand setting you mapping gets overwritten by YCM once you do your first expand.

So, summing up:

  • I've found no way for YCM and UltiSnips to share a common key.
  • The only way that works well for me is setting YCM and UltiSnips keys not to overlap.
@meonkeys

Bummer, still broken. I tried today with the latest YouCompleteMe and UltiSnips. @Chiel92's workaround (using different keys for UltiSnips) worked for me.

Whoops! This is expected behavior, see the FAQ (search for "YCM conflicts with UltiSnips TAB key usage". Sorry for the noise.

@lynndylanhurley

I'm having the same issue as @elmart. The snippet from this comment was working for me:
#36 (comment)

I ran an update this morning, and UltiSnips started complaining about deprecated method names.

I tried renaming the broken methods to this:

function! g:UltiSnips_Complete()
  call UltiSnips#ExpandSnippet()
  if g:ulti_expand_res == 0
    if pumvisible()
      return "\<C-n>"
    else
      call UltiSnips#JumpForwards()
      if g:ulti_jump_forwards_res == 0
        return "\<TAB>"
      endif
    endif
  endif
  return ""
endfunction

This silenced the errors, but now I don't get snippet expansion. Has anyone been able to solve this?

@lucapette

@lynndylanhurley this works for me:

let g:UltiSnipsExpandTrigger       = "<tab>"
let g:UltiSnipsJumpForwardTrigger  = "<tab>"
let g:UltiSnipsJumpBackwardTrigger = "<s-tab>"
let g:UltiSnipsSnippetDirectories  = ["snips"]

function! g:UltiSnips_Complete()
    call UltiSnips#ExpandSnippet()
    if g:ulti_expand_res == 0
        if pumvisible()
            return "\<C-n>"
        else
            call UltiSnips#JumpForwards()
            if g:ulti_jump_forwards_res == 0
               return "\<TAB>"
            endif
        endif
    endif
    return ""
endfunction

au InsertEnter * exec "inoremap <silent> " . g:UltiSnipsExpandTrigger . " <C-R>=g:UltiSnips_Complete()<cr>"

I'm using InsertEnter instead of BufEnter as suggested a few comments before since having switch buffer before getting the correct mapping is a bit annoying. I think it would be great to have the integration built-in. It's not ideal that such a good plugin doesn't play nicely with other famous plugins out of the box.

@kirk1h

i have added emmet to the script. it only expands emmet snippets starting with a . or #
works fine for me.

function! g:smart_tab()
  if (matchstr(getline("."), '^\s*#') != "") || (matchstr(getline("."), '^\s*\.') != "")
    call emmet#expandAbbr(3, "")
    return "\<esc>cit\<cr>\<esc>O"
  else
    call UltiSnips#ExpandSnippet()
    if g:ulti_expand_res == 0
      if pumvisible()
        return "\<C-n>"
      else
        call UltiSnips#JumpForwards()
        if g:ulti_jump_forwards_res == 0
          return "\<tab>"
        endif
      endif
    endif
    return ""
  endif
endfunction
let g:UltiSnipsJumpForwardTrigger="<tab>"
autocmd BufEnter * exec "inoremap <silent> " . g:UltiSnipsExpandTrigger . " <C-R>=g:smart_tab()<cr>"
@weitzj weitzj referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
@lynndylanhurley

@lucapette - that's working for me, thx :D

@frid frid referenced this issue from a commit in frid/vim-config2
@frid frid modify vimrc to let YCM and UltiSnipps work correctly 932f6d8
@bronson

@lucapette does that work when YCM pops up a completion box when you're typing inside an ultisnips completion? For example, I type:

def<tab>

And it expands perfectly to

def function_name| *args
  # TODO
end

Great so far. I type 'ta' for the function name, and YCM helpfully pops up a bunch of "table*" completions.

And now I'm stuck.

Hitting tab cycles through YCM's completions instead of moving to the args. Typing anything else cancels the UltiSnips entry. The only way for me to complete the function name is to type something that YCM can't complete, then hit tab, finish, then go back and fix the function name. Takes longer than just not using UltiSnips at all.

Does it work for you?

@jottr

@SirVer, @VAlloric could I kindly ask you guys to give a definitive answer in your respective docs on how to integrate YCM and Ultisnips?

Most people, judging from the length of this thread, would love to get them both work together and share the <Tab>-Trigger.

I've tried remapping Ultisnips to <c-somekey> just to discover that most key combinations in insert mode are used by other plugins/functions, I guess I won't be the only one with that issue. The space of available key combos in insert mode is tight and precious as it is already. Having two plugins, which could conveniently share the <Tab>-key use a different mapping seems to be an awful waste.

Both your plugins are an awesome addition to our toolbox, getting them to integrate nicely would be even awesomer.

@SirVer

The definite answer to use TAB is here: http://stackoverflow.com/a/18685821/200945

PHAT disclaimer though: overloading one key to do more than one function in Vim will come back to bite you because there will always be situations where there is ambiguity: do I want to complete this word or rather expand this as a trigger?

I have bug reports like once per month of people who map TAB to expand and jump forward and complain when UltiSnips can't read their mind what they actually want to do in a certain situation.

@bronson

I like that the StackOverflow answer was taken from higher up this thread.

In my experience, the definitive answer is: tell one of them not to use tab. Someone needs to fix all the corner cases before they can both use tab together.

It's a shame... that would be so cool.

@SirVer

I like that the StackOverflow answer was taken from higher up this thread.

I was told the SO answer is only based on the one further up, but the one on SO is fully copy & pastable and therefore 'better'. I have not verified this.

It's a shame... that would be so cool.

You are complaining about the wrong thing. The SO answer solves all technical issues as far as I know, so it is precisely what was asked for. It does not (and in fact can never) solve the semantic overloading issue:

Using it, if you hit tab, completion will happen if possible, otherwise UltiSnips gets its chance. It happens though that you want UltiSnips to act and not insert a completion. The tools cannot know when you want to do the one or the other - only you can. But if you put two different functions on one key, sometimes the wrong thing will happen. So just do not do it.

@bronson

I don't mean to complain. Just speculating that it would be nice if tab would do the visible YCM completion and, if that's not applicable, do an UltiSnips JumpForward.

I realize that's an irritating integration problem, though, and probably not worth the effort.

@SirVer

Just speculating that it would be nice if tab would do the visible YCM completion and, if that's not applicable, do an UltiSnips JumpForward.

that is what the snippet posted on SO does. Just use it.

@bronson

I did. Like I said, UltiSnips gets stuck when YCM has completions. The "if that's not applicable" logic doesn't exist today.

@cocodrino

guys I try the @kirk1h but seems doesnt works for me, I can't expand the snippet,

would be an option than if you highlight the snippet and press enter it expands...I don't know you but I will be happy with it :D ...I understand the @bronson point but an alternative would be close the suggestion with Esc and then press tab, if there are not suggestion then jumpforward , personally I don't like need press Esc for exit of YCM but I prefer it over other alternatives, I dont have many Ctrl keys free just now...

I suppose than pumvisible() would do the trick but my understand of vim script is pretty basic, let me know if it's possible and if a vim hero can write it...

@zfedoran

I had to make a few additions to get the script posted above working with the Enter key as the trigger. Posting it here in case someone else also has the same thing in mind.

(note: I haven't yet had time to test this thoroughly)

let g:UltiSnipsExpandTrigger       ="<c-tab>"
let g:UltiSnipsJumpForwardTrigger  = "<tab>"
let g:UltiSnipsJumpBackwardTrigger = "<s-tab>"

" Enable tabbing through list of results
function! g:UltiSnips_Complete()
    call UltiSnips#ExpandSnippet()
    if g:ulti_expand_res == 0
        if pumvisible()
            return "\<C-n>"
        else
            call UltiSnips#JumpForwards()
            if g:ulti_jump_forwards_res == 0
               return "\<TAB>"
            endif
        endif
    endif
    return ""
endfunction

au InsertEnter * exec "inoremap <silent> " . g:UltiSnipsExpandTrigger . " <C-R>=g:UltiSnips_Complete()<cr>"

" Expand snippet or return
let g:ulti_expand_res = 0
function! Ulti_ExpandOrEnter()
    call UltiSnips#ExpandSnippet()
    if g:ulti_expand_res
        return ''
    else
        return "\<return>"
endfunction

" Set <space> as primary trigger
inoremap <return> <C-R>=Ulti_ExpandOrEnter()<CR>
@consen

It’s better to make YCM not use Tab key, I just put these settings in my vimrc:

let g:ycm_key_list_select_completion=['<C-n>', '<Down>']
let g:ycm_key_list_previous_completion=['<C-p>', '<Up>']

let g:UltiSnipsExpandTrigger="<Tab>"
let g:UltiSnipsJumpForwardTrigger="<Tab>"                                           
let g:UltiSnipsJumpBackwardTrigger="<S-Tab>"

Then I use Ctrl-n to select completion and Tab to trigger snippet, it works well.

@fabianhjr

@consen thanks for the suggestion. Works like a charm over here. +1

@wincent wincent referenced this issue from a commit in wincent/wincent
@wincent wincent Vim: usher in a new era of autocompletion productivity
So, I'm using YouCompleteMe everywhere now, not just on my Mac, so I am
expecting to be doing a lot more autocompletion from here on. Time to
fix some long-held grievances I have with the way autocompletion is
working with UltiSnips, YouCompleteMe and Supertab.

Here's an example scenario.

I have a snippet `log` that expands to `console.log();`, with a
placeholder inside the parens. Now, say I have a file with:

   var fooBar = 1;

and I type:

    log<tab>

UltiSnips puts me here:

    console.log(|);
                ^
                (cursor here)

If I then type:

    console.log(fooB<tab>);

I wind up here:

    console.log(fooB);|
                      ^
                      (cursor here)

When what I really want is:

    console.log(fooBar|);
                      ^
                      (cursor here)

ie. if Supertab _can_ complete something, I want it to, otherwise I want
UltiSnips to get the tab.

With YouCompleteMe in the picture, the experience is even worse, because
you'll see the pop-up as soon as you start typing "fooB". Reflexively,
you'd think you could push `<Tab>` to expand the suggestion, but you
can't; you have to remember to push `<C-j>` or `<C-n>` or `<Down>` (ugh)
instead.

Historically, the way I've gotten YouCompleteMe and UltiSnips to play
nicely is as described here:

    http://0x3f.org/blog/make-youcompleteme-ultisnips-compatible/

Effectively:

- Override YouCompleteMe's default bindings, freeing up `<Tab>` and
  `<S-Tab>`; set a new completion binding like `<C-j>` or something
- Install Supertab and tell it to use the completion binding that you
  just set up (in other words, pressing `<Tab>` will get "forwarded" to
  the `<C-j>` or other binding that you set up for YouCompleteMe)
- Tell UltiSnips to use `<Tab>` and `<S-Tab>` to do its thing

So, this works pretty darn well, except for the awkwardness described
above. In this commit, we make things better with a trick similar to the
one described here:

  Valloric/YouCompleteMe#36 (comment)
  [via http://stackoverflow.com/questions/14896327/ultisnips-and-youcompleteme]

Specifically:

- Get rid of Supertab
- Make a custom function that does the following when `<Tab>` is pressed
  (note, the precedence here is different than in the linked examples):
  - Try to expand a snippet
  - If that doesn't work, try to cycle through completion options (if
    the YouCompleteMe popup is visible) and otherwise try to jump to the
    next UltiSnips placeholder
  - If none of this works, just do a normal tab
- Set up mappings for `<Tab>` and `<S-Tab>` that call this custom
  function; note that these have to happen inside an autocommand in
  order to overwrite the late-mapped default shortcuts set by
  YouCompleteMe (although, as I write this, I think that may not be true
  any more because I can select non-clashing mappings)
- Get rid of `g:UltiSnipsJumpBackwardTrigger` so that it doesn't
  overwrite our `<S-Tab>` mapping
- Set up `<CR>` to accept completion; this gives us an easy way to break
  out of an endless cycle when choosing YouCompleteMe completions inside
  an  UltiSnips placeholder

Some TODOs noted inline, but this basically works. It basically means:

- `<Tab>` to cycle completions, `<S-Tab>` in reverse
- `<Tab>` to expand snippets
- `<Tab>` to jump between placeholders (for now `<S-Tab>` doesn't work
  here, although I think I could make it do so; `<C-k> does work)
- `<Enter>` to get out of completion mode (as noted inline, may need to
  tap twice; not sure why, as the same happens with `<C-y>`)

This last behavior is a slight deviation from how Vim normally handles
autocomplete mappings (see `:h ins-completion-menu`). Basically, it
sometimes inserts newlines when you hit `<Enter>` during completion. I
find this annoying far more often than not, so I am happy to drop this
behavior in the name of progress.
0664b62
@wladston

I tested almost everyone's settings, @zfedoran's was the only one that correctly overloaded the tab key and let me select a snippet with the key. Thanks :) :+1:

@maonx

I set ctrl-j to trigger snippet and tab to seletc completion,it works well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.