diff --git a/README.md b/README.md index dfe97785..e2e0574e 100644 --- a/README.md +++ b/README.md @@ -526,28 +526,31 @@ Default: `30` let g:ycm_max_diagnostics_to_display = 30 -### The `g:ycm_key_select_completion` option +### The `g:ycm_key_list_select_completion` option -This option controls the key mapping used to select the first completion string. -Invoking it repeatedly cycles forward through the completion list. +This option controls the key mappings used to select the first completion +string. Invoking any of them repeatedly cycles forward through the completion +list. -Default: `` +Some users like adding `` to this list. - let g:ycm_key_select_completion = '' +Default: `['', '']` -### The `g:ycm_key_previous_completion` option + let g:ycm_key_list_select_completion = ['', ''] -This option controls the key mapping used to select the previous completion -string. Invoking it repeatedly cycles backwards through the completion list. +### The `g:ycm_key_list_previous_completion` option -Note that the default of `` means Shift-TAB. Also note that the default -mapping will probably only work in GUI Vim (Gvim or MacVim) and not in plain -console Vim because the terminal usually does not forward modifier key -combinations to Vim. +This option controls the key mappings used to select the previous completion +string. Invoking any of them repeatedly cycles backwards through the completion +list. -Default: `` +Note that one of the defaults is `` which means Shift-TAB. That mapping +will probably only work in GUI Vim (Gvim or MacVim) and not in plain console Vim +because the terminal usually does not forward modifier key combinations to Vim. - let g:ycm_key_previous_completion = '' +Default: `['', '']` + + let g:ycm_key_previous_completion = ['', ''] ### The `g:ycm_key_invoke_completion` option diff --git a/autoload/youcompleteme.vim b/autoload/youcompleteme.vim index 7156ce54..cb91d0e0 100644 --- a/autoload/youcompleteme.vim +++ b/autoload/youcompleteme.vim @@ -53,38 +53,13 @@ function! youcompleteme#Enable() augroup END call s:SetUpCompleteopt() + call s:SetUpKeyMappings() + call s:ForceSyntasticCFamilyChecker() if g:ycm_allow_changing_updatetime set ut=2000 endif - " Needed so that YCM is used as the syntastic checker - let g:syntastic_cpp_checkers = ['ycm'] - let g:syntastic_c_checkers = ['ycm'] - let g:syntastic_objc_checkers = ['ycm'] - let g:syntastic_objcpp_checkers = ['ycm'] - - " With this command, when the completion window is visible, the tab key - " (default) will select the next candidate in the window. In vim, this also - " changes the typed-in text to that of the candidate completion. - exe 'inoremap ' . g:ycm_key_select_completion . - \ ' pumvisible() ? "\" : "\' . g:ycm_key_select_completion .'"' - - " This selects the previous candidate for shift-tab (default) - exe 'inoremap ' . g:ycm_key_previous_completion . - \ ' pumvisible() ? "\" : "\' . g:ycm_key_previous_completion .'"' - - if strlen(g:ycm_key_invoke_completion) - " trigger omni completion, deselects the first completion - " candidate that vim selects by default - exe 'inoremap ' . g:ycm_key_invoke_completion . ' ' - endif - - if strlen(g:ycm_key_detailed_diagnostics) - exe 'nnoremap ' . g:ycm_key_detailed_diagnostics . - \ ' :YcmShowDetailedDiagnostic' - endif - py import sys py import vim exe 'python sys.path.insert( 0, "' . s:script_folder_path . '/../python" )' @@ -98,6 +73,60 @@ function! youcompleteme#Enable() endfunction +function! s:SetUpKeyMappings() + " The g:ycm_key_select_completion and g:ycm_key_previous_completion used to + " exist and are now here purely for the sake of backwards compatibility; we + " don't want to break users if we can avoid it. + + if exists('g:ycm_key_select_completion') && + \ index(g:ycm_key_list_select_completion, + \ g:ycm_key_select_completion) == -1 + call add(g:ycm_key_list_select_completion, g:ycm_key_select_completion) + endif + + if exists('g:ycm_key_previous_completion') && + \ index(g:ycm_key_list_previous_completion, + \ g:ycm_key_previous_completion) == -1 + call add(g:ycm_key_list_previous_completion, g:ycm_key_previous_completion) + endif + + for key in g:ycm_key_list_select_completion + " With this command, when the completion window is visible, the tab key + " (default) will select the next candidate in the window. In vim, this also + " changes the typed-in text to that of the candidate completion. + exe 'inoremap ' . key . + \ ' pumvisible() ? "\" : "\' . key .'"' + endfor + + + for key in g:ycm_key_list_previous_completion + " This selects the previous candidate for shift-tab (default) + exe 'inoremap ' . key . + \ ' pumvisible() ? "\" : "\' . key .'"' + endfor + + if strlen(g:ycm_key_invoke_completion) + " trigger omni completion, deselects the first completion + " candidate that vim selects by default + exe 'inoremap ' . g:ycm_key_invoke_completion . ' ' + endif + + if strlen(g:ycm_key_detailed_diagnostics) + exe 'nnoremap ' . g:ycm_key_detailed_diagnostics . + \ ' :YcmShowDetailedDiagnostic' + endif +endfunction + + +function! s:ForceSyntasticCFamilyChecker() + " Needed so that YCM is used as the syntastic checker + let g:syntastic_cpp_checkers = ['ycm'] + let g:syntastic_c_checkers = ['ycm'] + let g:syntastic_objc_checkers = ['ycm'] + let g:syntastic_objcpp_checkers = ['ycm'] +endfunction + + function! s:AllowedToCompleteInCurrentFile() " If the user set the current filetype as a filetype that YCM should ignore, " then we don't do anything diff --git a/plugin/youcompleteme.vim b/plugin/youcompleteme.vim index ec2a1d39..5708f872 100644 --- a/plugin/youcompleteme.vim +++ b/plugin/youcompleteme.vim @@ -80,11 +80,11 @@ let g:ycm_autoclose_preview_window_after_completion = let g:ycm_max_diagnostics_to_display = \ get( g:, 'ycm_max_diagnostics_to_display', 30 ) -let g:ycm_key_select_completion = - \ get( g:, 'ycm_key_select_completion', '' ) +let g:ycm_key_list_select_completion = + \ get( g:, 'ycm_key_list_select_completion', ['', ''] ) -let g:ycm_key_previous_completion = - \ get( g:, 'ycm_key_previous_completion', '' ) +let g:ycm_key_list_previous_completion = + \ get( g:, 'ycm_key_list_previous_completion', ['', ''] ) let g:ycm_key_invoke_completion = \ get( g:, 'ycm_key_invoke_completion', '' )