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:
parent
561dc26b86
commit
4b5cbdbc9d
31
README.md
31
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: `<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
|
||||
string. Invoking it repeatedly cycles backwards through the completion list.
|
||||
### The `g:ycm_key_list_previous_completion` option
|
||||
|
||||
Note that the default of `<S-TAB>` 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: `<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
|
||||
|
||||
|
@ -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 <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 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 <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()
|
||||
" If the user set the current filetype as a filetype that YCM should ignore,
|
||||
" then we don't do anything
|
||||
|
@ -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', '<TAB>' )
|
||||
let g:ycm_key_list_select_completion =
|
||||
\ get( g:, 'ycm_key_list_select_completion', ['<TAB>', '<Down>'] )
|
||||
|
||||
let g:ycm_key_previous_completion =
|
||||
\ get( g:, 'ycm_key_previous_completion', '<S-TAB>' )
|
||||
let g:ycm_key_list_previous_completion =
|
||||
\ get( g:, 'ycm_key_list_previous_completion', ['<S-TAB>', '<Up>'] )
|
||||
|
||||
let g:ycm_key_invoke_completion =
|
||||
\ get( g:, 'ycm_key_invoke_completion', '<C-Space>' )
|
||||
|
Loading…
Reference in New Issue
Block a user