diff --git a/README.md b/README.md index a1a1471c..2849db52 100644 --- a/README.md +++ b/README.md @@ -229,7 +229,10 @@ TODO, still WIP - If the offered completions are too broad, keep typing characters; YCM will continue refining the offered completions based on your input. - Use the TAB key to accept a completion and continue pressing TAB to cycle - through the completions. Use Ctrl+TAB (or Shift-TAB) to cycle backwards. + through the completions. Use Shift-TAB to cycle backwards. Note that if you're + using console Vim (that is, not Gvim or MacVim) then it's likely that the + Shift-TAB binding will not work because the console will not pass it to Vim. + You can remap the keys; see the options section below. ### Semantic Completion Engine Usage @@ -385,6 +388,47 @@ Default: `30` let g:ycm_max_diagnostics_to_display = 30 +### The `g:ycm_key_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. + +Default: `` + + let g:ycm_key_select_completion = '' + +### The `g:ycm_key_previous_completion` option + +This option controls the key mapping used to select the previous completion +string. Invoking it repeatedly cycles backwards through the completion list. + +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. + +Default: `` + + let g:ycm_key_previous_completion = '' + +### The `g:ycm_key_invoke_completion` option + +This option controls the key mapping used to invoke the completion menu for +semantic completion. By default, semantic completion is trigged automatically +after typing `.`, `->` and `::` in insert mode (if semantic completion support +has been compiled in). This key mapping can be used to trigger semantic +completion anywhere. Useful for searching for top-level functions and classes. + +Note that the default of `` means Ctrl-Space. 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. + + +Default: `` + + let g:ycm_key_invoke_completion = '' + FAQ --- diff --git a/autoload/youcompleteme.vim b/autoload/youcompleteme.vim index a1de258f..e821668d 100644 --- a/autoload/youcompleteme.vim +++ b/autoload/youcompleteme.vim @@ -58,14 +58,22 @@ function! youcompleteme#Enable() set ut=2000 endif - " With this command, when the completion window is visible, the tab key will - " select the next candidate in the window. In vim, this also changes the - " typed-in text to that of the candidate completion. - inoremap pumvisible() ? "\" : "\" + " 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 ctrl-tab or shift-tab - inoremap pumvisible() ? "\" : "\" - inoremap pumvisible() ? "\" : "\" + " This selects the previous candidate for shift-tab (default) + exe 'inoremap ' . g:ycm_key_previous_completion . + \ ' pumvisible() ? "\" : "\' . g:ycm_key_previous_completion .'"' + + " trigger omni completion, deselects the first completion + " candidate that vim selects by default + exe 'inoremap ' . g:ycm_key_invoke_completion . ' ' + + " TODO: make this a nicer, customizable map + nnoremap d :call ShowDetailedDiagnostic() py import sys py import vim @@ -73,13 +81,6 @@ function! youcompleteme#Enable() py import ycm py ycm_state = ycm.YouCompleteMe() - " trigger omni completion, deselects the first completion - " candidate that vim selects by default - inoremap - - " TODO: make this a nicer, customizable map - nnoremap d :call ShowDetailedDiagnostic() - " Calling this once solves the problem of BufRead/BufEnter not triggering for " the first loaded file. This should be the last command executed in this " function! diff --git a/plugin/youcompleteme.vim b/plugin/youcompleteme.vim index 6b5081cd..a276ebbf 100644 --- a/plugin/youcompleteme.vim +++ b/plugin/youcompleteme.vim @@ -76,6 +76,15 @@ 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_previous_completion = + \ get( g:, 'ycm_key_previous_completion', '' ) + +let g:ycm_key_invoke_completion = + \ get( g:, 'ycm_key_invoke_completion', '' ) + " This is basic vim plugin boilerplate let s:save_cpo = &cpo set cpo&vim