6.8 KiB
		
	
	
	
	
	
	
	
			
		
		
	
	title, description
| title | description | 
|---|---|
| SpaceVim autocomplete layer | Autocomplete code within SpaceVim, fuzzy find the candidates from multiple completion sources, expand snippet before cursor automatically | 
Home >> Layers >> autocomplete
Description
This layer provides auto-completion in SpaceVim.
The following completion engines are supported:
- nvim-cmp - neovim >= 0.9.0
 - neocomplete - vim with 
+lua - neocomplcache - vim without 
+lua - deoplete - neovim with 
+python3 - coc - vim >= 8.1 or neovim >= 0.3.1
 - YouCompleteMe - disabled by default, to enable ycm, see 
:h g:spacevim_enable_ycm - Completor - vim8 with 
+pythonor+python3 - asyncomplete - vim8 or neovim with 
timers 
Snippets are supported via neosnippet.
Install
To use this configuration layer, add the following snippet to your custom configuration file:
[[layers]]
  name = "autocomplete"
Configuration
Completion engine
By default, SpaceVim will choose the completion engine automatically based on your vim version. But you can choose the completion engine to be used with the following variable:
autocomplete_method: the possible values are:ycm: for YouCompleteMeneocomplcachecoc: coc.nvim which also provides language server protocol featuredeopleteasyncompletecompletornvim-cmp
here is an example:
[options]
    autocomplete_method = "deoplete"
Snippets engine
The default snippets engine is neosnippet, the also can be changed to ultisnips:
[options]
    snippet_engine = "ultisnips"
The following snippets repos have been added by default:
- Shougo/neosnippet-snippets : neosnippet's default snippets.
 - honza/vim-snippets : extra snippets
 
If the snippet_engine is neosnippet, the following directories will be used:
~/.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.
If the snippet_engine is ultisnips, the following directories will be used:
~/.SpaceVim/UltiSnips/: SpaceVim runtime snippets.~/.SpaceVim.d/UltiSnips/: custom global snippets../.SpaceVim.d/UltiSnips/: custom local snippets (project's snippets)
Complete parens
By default, the parens will be completed automatically, to disabled this feature:
[options]
    autocomplete_parens = false
Layer options
You can customize the user experience of autocompletion with the following layer variables:
auto_completion_return_key_behaviorset the action to perform when theReturn/Enterkey is pressed. the possible values are:completecompletes with the current selectionsmartcompletes with current selection and expand snippet or argvsnilBy default it iscomplete.
auto_completion_tab_key_behaviorset the action to perform when theTABkey is pressed, the possible values are:smartcycle candidates, expand snippets, jump parameterscompletecompletes with the current selectioncyclecompletes the common prefix and cycle between candidatesnilinsert a carriage return By default it iscomplete.
auto_completion_delayis a number to delay the completion after input in milliseconds, by default it is 50 ms.auto_completion_complete_with_key_sequenceis a string of two characters denoting a key sequence that will perform acompleteaction if the sequence as been entered quickly enough. If its value isnilthen the feature is disabled. NOTE: This option should not has same value asescape_key_bindingauto_completion_complete_with_key_sequence_delayis the number of seconds to wait for the autocompletion key sequence to be entered. The default value is 1 seconds. This option is used for vim'stimeoutlenoption in insert mode.
The default configuration of the layer is:
[[layers]]
  name = "autocomplete"
  auto_completion_return_key_behavior = "nil"
  auto_completion_tab_key_behavior = "smart"
  auto_completion_delay = 200
  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.
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 false.
[[layers]]
  name = "autocomplete"
  auto_completion_enable_snippets_in_popup = false
Key bindings
Completion
| Key bindings | Description | 
|---|---|
Ctrl-n | 
select next candidate | 
Ctrl-p | 
select previous candidate | 
<Tab> | 
based on auto_completion_tab_key_behavior | 
Shift-Tab | 
select previous candidate | 
<Return> | 
based on auto_completion_return_key_behavior | 
Snippets
| Key Binding | Description | 
|---|---|
M-/ | 
Expand a snippet if text before point is a prefix of a snippet | 
SPC i s | 
List all current snippets for inserting | 
<Leader> f s | 
Fuzzy find Ultisnips snippets if snippet_engine = "ultisnips" and the layer telescope is used. Thanks to telescope-ultisnips.nvim | 
NOTE: SPC i s requires that at least one fuzzy search layer be loaded. If the snippet_engine is neosnippet.
The fuzzy finder layer can be leaderf, denite or unite. For ultisnips, you can use leaderf or unite layer.