Mappings can now be easily remapped

This commit is contained in:
Strahinja Val Markovic 2013-01-26 18:45:27 -08:00
parent 60860d82f3
commit 9b3e009ed1
3 changed files with 69 additions and 15 deletions

View File

@ -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: `<TAB>`
let g:ycm_key_select_completion = '<TAB>'
### 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 `<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.
Default: `<S-TAB>`
let g:ycm_key_previous_completion = '<S-TAB>'
### 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 `<C-Space>` 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: `<C-Space>`
let g:ycm_key_invoke_completion = '<C-Space>'
FAQ
---

View File

@ -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 <expr><TAB> pumvisible() ? "\<C-n>" : "\<TAB>"
" 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 ctrl-tab or shift-tab
inoremap <expr><C-TAB> pumvisible() ? "\<C-p>" : "\<TAB>"
inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<TAB>"
" 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 .'"'
" <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>'
" TODO: make this a nicer, customizable map
nnoremap <unique> <leader>d :call <sid>ShowDetailedDiagnostic()<cr>
py import sys
py import vim
@ -73,13 +81,6 @@ function! youcompleteme#Enable()
py import ycm
py ycm_state = ycm.YouCompleteMe()
" <c-x><c-o> trigger omni completion, <c-p> deselects the first completion
" candidate that vim selects by default
inoremap <unique> <C-Space> <C-X><C-O><C-P>
" TODO: make this a nicer, customizable map
nnoremap <unique> <leader>d :call <sid>ShowDetailedDiagnostic()<cr>
" 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!

View File

@ -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', '<TAB>' )
let g:ycm_key_previous_completion =
\ get( g:, 'ycm_key_previous_completion', '<S-TAB>' )
let g:ycm_key_invoke_completion =
\ get( g:, 'ycm_key_invoke_completion', '<C-Space>' )
" This is basic vim plugin boilerplate
let s:save_cpo = &cpo
set cpo&vim