Multiple mappings possible for selection cycling

This change also makes the arrow keys behave like Tab and Shift-Tab.

Fixes issue #83.
This commit is contained in:
Strahinja Val Markovic 2013-02-08 18:29:36 -08:00
parent 561dc26b86
commit 4b5cbdbc9d
3 changed files with 77 additions and 45 deletions

View File

@ -526,28 +526,31 @@ Default: `30`
let g:ycm_max_diagnostics_to_display = 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. This option controls the key mappings used to select the first completion
Invoking it repeatedly cycles forward through the completion list. string. Invoking any of them repeatedly cycles forward through the completion
list.
Default: `<TAB>` Some users like adding `<Enter>` to this list.
let g:ycm_key_select_completion = '<TAB>' Default: `['<TAB>', '<Down>']`
### The `g:ycm_key_previous_completion` option let g:ycm_key_list_select_completion = ['<TAB>', '<Down>']
This option controls the key mapping used to select the previous completion ### The `g:ycm_key_list_previous_completion` option
string. Invoking it repeatedly cycles backwards through the completion list.
Note that the default of `<S-TAB>` means Shift-TAB. Also note that the default This option controls the key mappings used to select the previous completion
mapping will probably only work in GUI Vim (Gvim or MacVim) and not in plain string. Invoking any of them repeatedly cycles backwards through the completion
console Vim because the terminal usually does not forward modifier key list.
combinations to Vim.
Default: `<S-TAB>` Note that one of the defaults is `<S-TAB>` 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 = '<S-TAB>' Default: `['<S-TAB>', '<Up>']`
let g:ycm_key_previous_completion = ['<S-TAB>', '<Up>']
### The `g:ycm_key_invoke_completion` option ### The `g:ycm_key_invoke_completion` option

View File

@ -53,38 +53,13 @@ function! youcompleteme#Enable()
augroup END augroup END
call s:SetUpCompleteopt() call s:SetUpCompleteopt()
call s:SetUpKeyMappings()
call s:ForceSyntasticCFamilyChecker()
if g:ycm_allow_changing_updatetime if g:ycm_allow_changing_updatetime
set ut=2000 set ut=2000
endif 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 <expr>' . g:ycm_key_select_completion .
\ ' pumvisible() ? "\<C-n>" : "\' . g:ycm_key_select_completion .'"'
" This selects the previous candidate for shift-tab (default)
exe 'inoremap <expr>' . g:ycm_key_previous_completion .
\ ' pumvisible() ? "\<C-p>" : "\' . g:ycm_key_previous_completion .'"'
if strlen(g:ycm_key_invoke_completion)
" <c-x><c-o> trigger omni completion, <c-p> deselects the first completion
" candidate that vim selects by default
exe 'inoremap <unique> ' . g:ycm_key_invoke_completion . ' <C-X><C-O><C-P>'
endif
if strlen(g:ycm_key_detailed_diagnostics)
exe 'nnoremap <unique> ' . g:ycm_key_detailed_diagnostics .
\ ' :YcmShowDetailedDiagnostic<cr>'
endif
py import sys py import sys
py import vim py import vim
exe 'python sys.path.insert( 0, "' . s:script_folder_path . '/../python" )' exe 'python sys.path.insert( 0, "' . s:script_folder_path . '/../python" )'
@ -98,6 +73,60 @@ function! youcompleteme#Enable()
endfunction 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 <expr>' . key .
\ ' pumvisible() ? "\<C-n>" : "\' . key .'"'
endfor
for key in g:ycm_key_list_previous_completion
" This selects the previous candidate for shift-tab (default)
exe 'inoremap <expr>' . key .
\ ' pumvisible() ? "\<C-p>" : "\' . key .'"'
endfor
if strlen(g:ycm_key_invoke_completion)
" <c-x><c-o> trigger omni completion, <c-p> deselects the first completion
" candidate that vim selects by default
exe 'inoremap <unique> ' . g:ycm_key_invoke_completion . ' <C-X><C-O><C-P>'
endif
if strlen(g:ycm_key_detailed_diagnostics)
exe 'nnoremap <unique> ' . g:ycm_key_detailed_diagnostics .
\ ' :YcmShowDetailedDiagnostic<cr>'
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() function! s:AllowedToCompleteInCurrentFile()
" If the user set the current filetype as a filetype that YCM should ignore, " If the user set the current filetype as a filetype that YCM should ignore,
" then we don't do anything " then we don't do anything

View File

@ -80,11 +80,11 @@ let g:ycm_autoclose_preview_window_after_completion =
let g:ycm_max_diagnostics_to_display = let g:ycm_max_diagnostics_to_display =
\ get( g:, 'ycm_max_diagnostics_to_display', 30 ) \ get( g:, 'ycm_max_diagnostics_to_display', 30 )
let g:ycm_key_select_completion = let g:ycm_key_list_select_completion =
\ get( g:, 'ycm_key_select_completion', '<TAB>' ) \ get( g:, 'ycm_key_list_select_completion', ['<TAB>', '<Down>'] )
let g:ycm_key_previous_completion = let g:ycm_key_list_previous_completion =
\ get( g:, 'ycm_key_previous_completion', '<S-TAB>' ) \ get( g:, 'ycm_key_list_previous_completion', ['<S-TAB>', '<Up>'] )
let g:ycm_key_invoke_completion = let g:ycm_key_invoke_completion =
\ get( g:, 'ycm_key_invoke_completion', '<C-Space>' ) \ get( g:, 'ycm_key_invoke_completion', '<C-Space>' )