Closed codemuse closed 11 years ago
I'm in the same boat here. I can learn to live without it, but this feature is so eerily similar to Xcode's awesome autocompletion that it's hard to unlearn the years of muscle memory.
@kballenegger I use Linux Vim/Gvim daily at work for C/C++/Python projects, but work on iOS projects in my spare time with Xcode, so I switch between the two on a daily basis... I think many people using a combination of both Xcode and Vim would like to have their autocomplete mechanisms to kind-of work the same.
Not to say that YCM isn't a vast improvement over any other existing Vim autocompletion systems, so kudos to @Valloric.
I have to admit that you guys are slowly convincing me that enter should at least be a "noop" key. AFAIK Xcode separates cycling through the list of candidates and selecting one whereas YCM does this differently. With YCM, cycling is selecting an item at the same time as well, since after you highlight an item in the menu the identifier is already inserted in the buffer; you don't need to confirm it with enter or anything, you just move on.
I prefer this over what most IDE's do, which is just needlessly forcing the user to press an extra key to "accept" the completion.
I could make it so that pressing enter in the list doesn't do anything (or close the menu, but I'm not sure how easy that would be). I'll look into this.
But at the very least, the arrow keys should also do the YCM default of selecting an item in the menu also inserts it in the buffer.
Ok, so arrow keys now work like tab/shift-tab. You can also add enter to the list of keys for cycling.
Other than that, I'm not a fan of making enter a "noop" key just because some users have developed muscle memory for it. I could be convinced otherwise, but for now try it like this; the arrow keys behaving like tab/shift-tab should go a long way.
Thank you, never do the enter "noop" key please , that is unefficient.
I think <enter>
as <nop>
or as "dismiss menu" would be ideal. That said, considering how it doesn't seem to be to everbody's taste, I think making this a configurable option would be the best solution.
let g:ycm_completion_confirm_key = '<enter>'
This binding would simply have the effect of dismissing the completion menu.
I've just updated and tried it out and it does work a lot better like this with the arrow keys actually inserting the selection directly. I've still kept <enter>
in the list of selection cycle keys as I want to be able to hit enter to select and insert the first match while I'm typing.
I took a glance at the source code of your plugin to see if there'd be an easy fix (e.g. a key remap) to let enter behave differently when you have already selected a match, so I could just do some local configuration or source code change. Though, as far as I can see, there's no easy fix for that unfortunately. After looking at how YCM uses the popup menu I better understand that the way "normal" IDEs work is very different from the way the popup menu works in Vim.
Although it's not 100% perfect to my personal taste, I guess I could learn to live with the current situation.
Yeah, there's no easy way to close the popup menu without selecting an item. If there were, I'd add an option to make enter close it.
Well, thanks for considering the options and thinking along; obviously YCM is constrained by the API that Vim provides. For what I have seen it's fairly limited. Still YCM is really a leap forward in autocompletion for Vim, and it's a pleasure to use.
@Valloric Yeah, I want to echo what @codemuse just said. Thanks so much for being an awesome open source project lead, keeping an open mind about this and giving it a shot! YCM is amazing, don't let our nitpicking let you think otherwise.
I'd also like to add my +1 to @codemuse's idea of
I definitely see the logic in the present system. However, the popup window does take over some key mappings (i.e., down/tab and up/s-tab) which I'd like to be able to use after finishing a completion.
Right now if I want to select a completion, then move down to the next line and continue typing, I have to type something like toS
I tried playing around with mapping
I played around with using feedkey(),
Perhaps one solution would be to not show that second popup? Don't know if that'd be any easier to implement, but even apart from this feature request, it doesn't seem useful to have it on-screen after choosing a completion in the first popup -- it just suggests the already completed word.
I'd be happy to hack around if you could give me a pointer on a method that might work for implementing the above features. Truly appreciate your work here, it's been greatly useful to me.
Coming back to an old issue - I just started using YCM and am also ending up with extra newlines because I'm also used to pressing enter to finalize the completion dialog. As @int3h suggests, C-Y works, but mapping enter to C-Y does not, for some reason. I understand that it's aparrantly tricky to just close the dialog on enter, but I'd like to voice my support in case it's ever possible :-)
In case anyone else stumbles upon this: what does seem to work (but is kind of a hack because it leaves insert mode using
:inoremap <expr> <Enter> pumvisible() ? "<Esc>a" : "<Enter>"
(trick taken from here: https://github.com/Valloric/YouCompleteMe/issues/76#issuecomment-13344762)
Also coming back from an old issue :)
I am not a user of IDE's or autocomplete (other then the shell's tab) and decided to give ycm as an autocomplete helper.
I have since entered a number of wrong frustrating enters. What I do, and maybe I'm using the plugin wrong, is
In order to cycle through options, I was trying to use the same key I was using for opening the completion dialogue.
In case anyone needs it, here's how I did it:
" disable auto_triggering ycm suggestions pane and instead
" use semantic completion only on Ctrl+n
let ycm_trigger_key = '<C-n>'
let g:ycm_auto_trigger = 0
let g:ycm_key_invoke_completion = ycm_trigger_key
" this is some arcane magic to allow cycling through the YCM options
" with the same key that opened it.
" See http://vim.wikia.com/wiki/Improve_completion_popup_menu for more info.
let g:ycm_key_list_select_completion = ['<TAB>', '<C-j>']
inoremap <expr> ycm_trigger_key pumvisible() ? "<C-j>" : ycm_trigger_key;
Choosing the return key as select key gives weird behaviour when you cycle through the list with arrows keys and then try to select the entry by pressing enter. Now you could argue that choosing the return key as select key is not a good idea, however It does work fine to select the first entry, without needing to cycle, so in that sense it is not a strange choice.
See also #79, where @Valloric proposes to let the arrow keys work as real cycle keys, removing the need to press enter when cycling through options. It would at least remove the need to press enter when cycling with arrow keys, although if you would press enter, I guess it'll still choose the next completion in the list.
Well, as @kaballenegger comments in #76, being used to Xcode I should train myself not to press enter in Vim.