diff --git a/README.md b/README.md index f6b685b8..dd31e4ed 100644 --- a/README.md +++ b/README.md @@ -2825,11 +2825,10 @@ details. If you want to see which tag files YCM will read for a given buffer, run `:echo tagfiles()` with the relevant buffer active. Note that that function will only list tag files that already exist. -### `CTRL-U` in insert mode does not work +### `CTRL-U` in insert mode does not work while the completion menu is visible -YCM keeps you in a `completefunc` completion mode when you're typing in insert -mode and Vim disables `` in completion mode as a "feature." Sadly there's -nothing I can do about this. +YCM uses `completefunc` completion mode to show suggestions and Vim disables +`` in that mode as a "feature." Sadly there's nothing I can do about this. ### YCM conflicts with UltiSnips TAB key usage diff --git a/autoload/youcompleteme.vim b/autoload/youcompleteme.vim index 823b134f..c813d386 100644 --- a/autoload/youcompleteme.vim +++ b/autoload/youcompleteme.vim @@ -546,14 +546,19 @@ function! s:SendKeys( keys ) endfunction -function! s:OnInsertChar() - call timer_stop( s:pollers.completion.id ) +function! s:CloseCompletionMenu() if pumvisible() call s:SendKeys( "\" ) endif endfunction +function! s:OnInsertChar() + call timer_stop( s:pollers.completion.id ) + call s:CloseCompletionMenu() +endfunction + + function! s:OnDeleteChar( key ) call timer_stop( s:pollers.completion.id ) if pumvisible() @@ -751,25 +756,26 @@ endfunction function! s:Complete() - " invokes the user's completion function (which we have set to - " youcompleteme#CompleteFunc), and tells Vim to select the previous - " completion candidate. This is necessary because by default, Vim selects the - " first candidate when completion is invoked, and selecting a candidate - " automatically replaces the current text with it. Calling forces Vim to - " deselect the first candidate and in turn preserve the user's current text - " until he explicitly chooses to replace it with a completion. - call s:SendKeys( "\\\" ) + " Do not call user's completion function if the start column is after the + " current column or if there are no candidates. Close the completion menu + " instead. This avoids keeping the user in completion mode. + if s:completion.start_column > col( '.' ) || empty( s:completion.candidates ) + call s:CloseCompletionMenu() + else + " invokes the user's completion function (which we have set to + " youcompleteme#CompleteFunc), and tells Vim to select the previous + " completion candidate. This is necessary because by default, Vim selects the + " first candidate when completion is invoked, and selecting a candidate + " automatically replaces the current text with it. Calling forces Vim to + " deselect the first candidate and in turn preserve the user's current text + " until he explicitly chooses to replace it with a completion. + call s:SendKeys( "\\\" ) + endif endfunction function! youcompleteme#CompleteFunc( findstart, base ) if a:findstart - if s:completion.start_column > col( '.' ) || - \ empty( s:completion.candidates ) - " For vim, -2 means not found but don't trigger an error message. - " See :h complete-functions. - return -2 - endif return s:completion.start_column - 1 endif return s:completion.candidates diff --git a/doc/youcompleteme.txt b/doc/youcompleteme.txt index 7f5895dc..0633fb58 100644 --- a/doc/youcompleteme.txt +++ b/doc/youcompleteme.txt @@ -148,7 +148,7 @@ Contents ~ 15. I get 'Fatal Python error: PyThreadState_Get: no current thread' on startup |youcompleteme-i-get-fatal-python-error-pythreadstate_get-no-current-thread-on-startup| 16. 'install.py' says python must be compiled with '--enable-framework'. Wat? |youcompleteme-install.py-says-python-must-be-compiled-with-enable-framework-.-wat| 17. YCM does not read identifiers from my tags files |youcompleteme-ycm-does-not-read-identifiers-from-my-tags-files| - 18. 'CTRL-U' in insert mode does not work |youcompleteme-ctrl-u-in-insert-mode-does-not-work| + 18. 'CTRL-U' in insert mode does not work while the completion menu is visible |youcompleteme-ctrl-u-in-insert-mode-does-not-work-while-completion-menu-is-visible| 19. YCM conflicts with UltiSnips TAB key usage |youcompleteme-ycm-conflicts-with-ultisnips-tab-key-usage| 20. Snippets added with ':UltiSnipsAddFiletypes' do not appear in the popup menu |youcompleteme-snippets-added-with-ultisnipsaddfiletypes-do-not-appear-in-popup-menu| 21. Why isn't YCM just written in plain VimScript, FFS? |youcompleteme-why-isnt-ycm-just-written-in-plain-vimscript-ffs| @@ -3087,12 +3087,11 @@ buffer, run ':echo tagfiles()' with the relevant buffer active. Note that that function will only list tag files that already exist. ------------------------------------------------------------------------------- - *youcompleteme-ctrl-u-in-insert-mode-does-not-work* -'CTRL-U' in insert mode does not work ~ +*youcompleteme-ctrl-u-in-insert-mode-does-not-work-while-completion-menu-is-visible* +'CTRL-U' in insert mode does not work while the completion menu is visible ~ -YCM keeps you in a 'completefunc' completion mode when you're typing in insert -mode and Vim disables '' in completion mode as a "feature." Sadly there's -nothing I can do about this. +YCM uses 'completefunc' completion mode to show suggestions and Vim disables +'' in that mode as a "feature." Sadly there's nothing I can do about this. ------------------------------------------------------------------------------- *youcompleteme-ycm-conflicts-with-ultisnips-tab-key-usage*