diff --git a/autoload/SpaceVim/default.vim b/autoload/SpaceVim/default.vim index bb4523682..46891901e 100644 --- a/autoload/SpaceVim/default.vim +++ b/autoload/SpaceVim/default.vim @@ -165,17 +165,6 @@ endfunction function! SpaceVim#default#SetMappings() abort - "mapping - imap SpaceVim#mapping#tab#i_tab() - imap pumvisible() ? "\" : "" - imap SpaceVim#mapping#shift_tab() - smap neosnippet#expandable_or_jumpable() ? "\(neosnippet_expand_or_jump)" : (complete_parameter#jumpable(1) ? "\(complete_parameter#goto_next_parameter)" : "\") - imap SpaceVim#mapping#enter#i_enter() - inoremap pumvisible() ? "\" : "\" - inoremap pumvisible() ? "\" : "\" - inoremap pumvisible() ? "\\\" : "\" - inoremap pumvisible() ? "\\\" : "\" - smap pumvisible() ? "\" : "" " Save a file with sudo " http://forrst.com/posts/Use_w_to_sudo_write_a_file_with_Vim-uAN cnoremap w!! %!sudo tee > /dev/null % diff --git a/autoload/SpaceVim/layers/autocomplete.vim b/autoload/SpaceVim/layers/autocomplete.vim index 90f369866..ecb2f1b7e 100644 --- a/autoload/SpaceVim/layers/autocomplete.vim +++ b/autoload/SpaceVim/layers/autocomplete.vim @@ -19,7 +19,6 @@ " SpaceVim will not append `./.SpaceVim/snippets` as default snippets directory. - function! SpaceVim#layers#autocomplete#plugins() abort let plugins = [ \ ['honza/vim-snippets', { 'on_event' : 'InsertEnter', 'loadconf_before' : 1}], @@ -72,6 +71,36 @@ function! SpaceVim#layers#autocomplete#config() abort endif let g:delimitMate_matchpairs = '[:],{:},<:>' inoremap ( complete_parameter#pre_complete("()") + "mapping + imap SpaceVim#mapping#tab#i_tab() + imap pumvisible() ? "\" : "" + imap SpaceVim#mapping#shift_tab() + smap neosnippet#expandable_or_jumpable() ? "\(neosnippet_expand_or_jump)" : (complete_parameter#jumpable(1) ? "\(complete_parameter#goto_next_parameter)" : "\") + imap SpaceVim#mapping#enter#i_enter() + smap pumvisible() ? "\" : "" + + + inoremap pumvisible() ? "\" : "\" + inoremap pumvisible() ? "\" : "\" + inoremap pumvisible() ? "\\\" : "\" + inoremap pumvisible() ? "\\\" : "\" +endfunction + +function! SpaceVim#layers#autocomplete#set_variable(var) + + let s:return_key_behavior = get(a:var, + \ 'auto-completion-return-key-behavior', + \ 'nil') + let s:tab_key_behavior = get(a:var, + \ 'auto-completion-tab-key-behavior', + \ 'smart') + let s:key_sequence = get(a:var, + \ 'auto-completion-complete-with-key-sequence', + \ 'nil') + let s:key_sequence_delay = get(a:var, + \ 'auto-completion-complete-with-key-sequence-delay', + \ 0.1) + endfunction diff --git a/docs/layers/autocomplete.md b/docs/layers/autocomplete.md index 116933dfe..5d9eeb1e3 100644 --- a/docs/layers/autocomplete.md +++ b/docs/layers/autocomplete.md @@ -9,6 +9,11 @@ title: "SpaceVim autocomplete layer" * [Install](#install) * [Configuration](#configuration) * [Key bindings](#key-bindings) + * [Snippets directories](#snippets-directories) + * [Show snippets in auto-completion popup](#show-snippets-in-auto-completion-popup) +* [Key bindings](#key-bindings-1) + * [auto-complete](#auto-complete) + * [Neosnippet](#neosnippet) @@ -39,16 +44,72 @@ call SpaceVim#layers#load('autocomplete') You can customize the user experience of auto-completion with the following layer variables: -1. `auto-completion-return-key-behavior` set the action to perform when the `RET` key is pressed, the possible values are: - - `complete` completes with the current selection - - `nil` does nothing -2. `auto-completion-tab-key-behavior` set the action to perform when the `TAB` key is pressed, the possible values are: - - `smart` cycle candidates, expand snippets, jump parameters - - `complete` completes with the current selection - - `cycle` completes the common prefix and cycle between candidates - - `nil` does nothing -3. `auto-completion-complete-with-key-sequence` is a string of two characters denoting a key sequence that will perform a `complete` action if the sequence as been entered quickly enough. If its value is `nil` then the feature is disabled. -4. `auto-completion-complete-with-key-sequence-delay` is the number of seconds to wait for the auto-completion key sequence to be entered. The default value is 0.1 seconds. +1. `auto-completion-return-key-behavior` set the action to perform when the `RET` key is pressed, the possible values are: + +- `complete` completes with the current selection +- `nil` does nothing + +2. `auto-completion-tab-key-behavior` set the action to perform when the `TAB` key is pressed, the possible values are: + +- `smart` cycle candidates, expand snippets, jump parameters +- `complete` completes with the current selection +- `cycle` completes the common prefix and cycle between candidates +- `nil` does nothing + +3. `auto-completion-complete-with-key-sequence` is a string of two characters denoting a key sequence that will perform a `complete` action if the sequence as been entered quickly enough. If its value is `nil` then the feature is disabled. +4. `auto-completion-complete-with-key-sequence-delay` is the number of seconds to wait for the auto-completion key sequence to be entered. The default value is 0.1 seconds. The default configuration of the layer is: +```vim +call SpaceVim#layers#load('autocomplete', { + \ 'auto-completion-return-key-behavior' : 'nil', + \ 'auto-completion-tab-key-behavior' : 'smart', + \ 'auto-completion-complete-with-key-sequence' : 'nil', + \ 'auto-completion-complete-with-key-sequence-delay' : 0.1, + \ }) +``` + +`jk` is a good candidate for `auto-completion-complete-with-key-sequence` if you don’t use it already. + +### Snippets directories + +The following snippets or directories are added by default: + +- [Shougo/neosnippet-snippets](https://github.com/Shougo/neosnippet-snippets) : neosnippet's default snippets. +- [honza/vim-snippets](https://github.com/honza/vim-snippets) : extra snippets +- `~/.SpaceVim/snippets/` : SpaceVim runtime snippets. +- `~/.SpaceVim.d/snippets/` : custom global snippets. +- `./.SpaceVim.d/snippets/` : custom local snippets (project's snippets) + +You can provide additional directories by setting the variable `g:neosnippet#snippets_directory` which can take a string in case of a single path or a list of paths. + +### Show snippets in auto-completion popup + +By default, snippets are shown in the auto-completion popup. To disable this feature, set the variable `auto-completion-enable-snippets-in-popup` to 0. + +```vim +call SpaceVim#layers#load('autocomplete', { + \ 'auto-completion-enable-snippets-in-popup' : 0 + \ }) +``` + +## Key bindings + +### auto-complete + +| Key bindings | Description | +| ------------ | -------------------------------------------------------------------- | +| `` | select next candidate | +| `` | select previous candidate | +| `` | expand selection or select next candidate | +| `` | select previous candidate | +| `` | complete word, if word is already completed insert a carriage return | + +### Neosnippet + +| Key Binding | Description | +| ----------- | -------------------------------------------------------------- | +| `M-/` | Expand a snippet if text before point is a prefix of a snippet | +| `SPC i s` | List all current yasnippets for inserting | +