1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-01-24 06:40:05 +08:00
SpaceVim/docs/layers/autocomplete.md

186 lines
6.6 KiB
Markdown
Raw Normal View History

2017-07-30 06:53:54 +08:00
---
title: "SpaceVim autocomplete layer"
description: "Autocomplete code within SpaceVim, fuzzy find the candidates from multiple completion sources, expand snippet before cursor automatically"
2017-07-30 06:53:54 +08:00
---
2019-10-14 23:29:07 +08:00
# [Home](../../) >> [Layers](../) >> autocomplete
2017-07-30 06:53:54 +08:00
<!-- vim-markdown-toc GFM -->
- [Description](#description)
- [Install](#install)
- [Configuration](#configuration)
2019-10-01 11:34:24 +08:00
- [Completion engine](#completion-engine)
2020-08-30 23:31:09 +08:00
- [Snippets engine](#snippets-engine)
2019-10-01 11:34:24 +08:00
- [Complete parens](#complete-parens)
- [Layer options](#layer-options)
- [Show snippets in auto-completion popup](#show-snippets-in-auto-completion-popup)
2019-10-01 11:34:24 +08:00
- [Key bindings](#key-bindings)
- [Completion](#completion)
- [Snippets](#snippets)
2017-07-30 06:53:54 +08:00
<!-- vim-markdown-toc -->
## Description
2021-06-21 20:39:29 +08:00
This layer provides auto-completion in SpaceVim.
2017-07-30 06:53:54 +08:00
The following completion engines are supported:
2018-10-06 10:15:19 +08:00
- [neocomplete](https://github.com/Shougo/neocomplete.vim) - vim with `+lua`
- [neocomplcache](https://github.com/Shougo/neocomplcache.vim) - vim without `+lua`
- [deoplete](https://github.com/Shougo/deoplete.nvim) - neovim with `+python3`
- [coc](https://github.com/neoclide/coc.nvim) - vim >= 8.1 or neovim >= 0.3.1
2018-10-06 10:15:19 +08:00
- [YouCompleteMe](https://github.com/Valloric/YouCompleteMe) - disabled by default, to enable ycm, see `:h g:spacevim_enable_ycm`
- [Completor](https://github.com/maralla/completor.vim) - vim8 with `+python` or `+python3`
- [asyncomplete](https://github.com/prabirshrestha/asyncomplete.vim) - vim8 or neovim with `timers`
2017-07-30 06:53:54 +08:00
Snippets are supported via [neosnippet](https://github.com/Shougo/neosnippet.vim).
## Install
2021-06-21 20:39:29 +08:00
To use this configuration layer, add the following snippet to your custom configuration file:
2017-07-30 06:53:54 +08:00
2018-06-23 14:37:41 +08:00
```toml
[[layers]]
name = "autocomplete"
2017-07-30 06:53:54 +08:00
```
2017-04-29 21:49:49 +08:00
2017-07-30 07:15:13 +08:00
## Configuration
2019-10-01 11:34:24 +08:00
### Completion engine
2021-06-21 20:39:29 +08:00
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:
2019-10-01 11:34:24 +08:00
- `autocomplete_method`: the possible values are:
- `ycm`: for YouCompleteMe
- `neocomplcache`
- `coc`: coc.nvim which also provides language server protocol feature
- `deoplete`
- `asyncomplete`
- `completor`
2019-10-01 11:34:24 +08:00
here is an example:
2017-07-30 07:15:13 +08:00
2019-10-01 11:34:24 +08:00
```toml
[options]
autocomplete_method = "deoplete"
```
2020-08-30 23:31:09 +08:00
### Snippets engine
The default snippets engine is `neosnippet`, the also can be changed to `ultisnips`:
```toml
[options]
snippet_engine = "ultisnips"
```
The following snippets repos have been 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
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)
2019-10-01 11:34:24 +08:00
### Complete parens
By default, the parens will be completed automatically, to disabled this feature:
```toml
[options]
autocomplete_parens = false
```
2017-07-30 07:15:13 +08:00
2019-10-01 11:34:24 +08:00
### Layer options
You can customize the user experience of autocompletion with the following layer variables:
1. `auto_completion_return_key_behavior` set the action to perform
2021-06-21 20:39:29 +08:00
when the `Return`/`Enter` key is pressed. the possible values are:
2018-10-06 10:15:19 +08:00
- `complete` completes with the current selection
- `smart` completes with current selection and expand snippet or argvs
2019-01-07 21:15:22 +08:00
- `nil`
By default it is `complete`.
2019-10-01 11:34:24 +08:00
2. `auto_completion_tab_key_behavior` set the action to
perform when the `TAB` key is pressed, the possible values are:
2018-10-06 10:15:19 +08:00
- `smart` cycle candidates, expand snippets, jump parameters
- `complete` completes with the current selection
- `cycle` completes the common prefix and cycle between candidates
- `nil` insert a carriage return
By default it is `complete`.
2019-10-01 11:34:24 +08:00
3. `auto_completion_delay` is a number to delay the completion after input in milliseconds,
by default it is 50 ms.
4. `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.
**NOTE:** This option should not has same value as `escape_key_binding`
2019-10-01 11:34:24 +08:00
5. `auto_completion_complete_with_key_sequence_delay` is 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's `timeoutlen` option in insert mode.
2017-07-30 07:15:13 +08:00
The default configuration of the layer is:
2018-10-06 10:15:19 +08:00
```toml
[[layers]]
name = "autocomplete"
2019-10-01 11:34:24 +08:00
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
2017-08-01 05:35:21 +08:00
```
2019-10-01 11:34:24 +08:00
`jk` is a good candidate for `auto_completion_complete_with_key_sequence` if you dont use it already.
2017-08-01 05:35:21 +08:00
### Show snippets in auto-completion popup
2019-10-01 11:34:24 +08:00
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.
2017-08-01 05:35:21 +08:00
2019-10-01 11:34:24 +08:00
```toml
[[layers]]
name = "autocomplete"
auto_completion_enable_snippets_in_popup = false
2017-08-01 05:35:21 +08:00
```
## Key bindings
2019-10-01 11:34:24 +08:00
### Completion
2017-08-01 05:35:21 +08:00
2021-06-21 20:39:29 +08:00
| 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` |
2017-08-01 05:35:21 +08:00
### Snippets
2017-08-01 05:35:21 +08:00
| 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 |
2022-02-03 20:31:06 +08:00
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.