Vim-EasyComplete
A Fast & Minimalism Style Code Completion Plugin for vim/nvim.
Why
There are many excellent vim auto-completion plugins such as nvim-cmp, vim-lsp, YouCompleteMe and coc.nvim etc. I used coc.nvim for a long time. It’s experience is good. But there are a few things I don’t like. These plugins tend to have too much dependencies and do not have minimal configuration. For example, I don't want to install Node when programming c++ or golang. In my opinion vim is more lightweight than vscode so I don’t need the fully integrated features of it. Besides other completion plugins neither have good experiences enough nor compatible with vim and nvim at the same time. Therefor I created vim-easycomplete according to my personal habits.
What
Vim-easycomplete is a fast and minimalism style completion plugin for vim/nvim. The goal is to work everywhere out of the box with high-speed performance. It requires pure vim script. You don’t need to configure anything. Especially, You don’t have to install Node and a bunch of Node modules unless you’re a javascript/typescript programmer.
It is easy to install and use. It contains these features:
- Buffer Keywords/Directory support
- LSP(language-server-protocol) support
- TabNine support. (Highly Recommend!)
- Easy to install LSP Server with one command
- Written in pure vim script for vim8 and neovim
- Snippet support with ultisnips.
- Fast performance
The reason I decided to use pure vim script instead of lua or python is that I want a wider range of compatibility. And I made a lot of async handling with vim script to avoid the block of vim.
Installation
Easycomplete requires Vim 8.2 or higher version with MacOS/Linux/FreeBSD. For neovim users, 0.4.4 or higher is required.
For vim-plug:
Plug 'jayli/vim-easycomplete'
Plug 'SirVer/ultisnips'
Run :PlugInstall
.
For dein.vim
call dein#add('jayli/vim-easycomplete')
call dein#add('SirVer/ultisnips')
For Packer.nvim
use { 'jayli/vim-easycomplete' }
use { 'SirVer/ultisnips' }
Run :PackerInstall
You can use my default configuration here with lua.
All Supported Commands
All commands:
Command | Description |
---|---|
:EasyCompleteInstallServer |
Install LSP server for current fileytpe |
:InstallLspServer |
Same as EasyCompleteInstallServer |
:EasyCompleteDisable |
Disable EasyComplete |
:EasyCompleteEnable |
Enable EasyComplete |
:EasyCompleteGotoDefinition |
Goto definition position |
:EasyCompleteReference |
Find references |
:EasyCompleteRename |
Rename |
:EasyCompleteCheck |
Checking LSP server |
:EasyCompletePreviousDiagnostic |
Goto Previous diagnostic |
:EasyCompleteNextDiagnostic |
Goto Next diagnostic |
:EasyCompleteProfileStart |
Start record diagnostics message |
:EasyCompleteProfileStop |
Stop record diagnostics message |
:EasyCompleteLint |
Do diagnostic |
:LintEasyComplete |
Do diagnostic |
:BackToOriginalBuffer |
Return to the position before the reference jump |
:DenoCache |
Do Deno Cache for downloading modules |
:CleanLog |
close quickfix window |
Configuration
The plugin is out of box and config nothing. (If you want full features, please refer to my full configuration)
Usage
Use Tab to trigger the completion suggestions and select matched items. By default use Ctrl-]
for definition jumping, Ctrl-t
for jumping back (Same as tags jumping).
With vim script:
noremap gr :EasyCompleteReference<CR>
noremap gd :EasyCompleteGotoDefinition<CR>
noremap rn :EasyCompleteRename<CR>
noremap gb :BackToOriginalBuffer<CR>
or with lua:
vim.keymap.set('n', 'gr', ':EasyCompleteReference<CR>')
vim.keymap.set('n', 'gd', ':EasyCompleteGotoDefinition<CR>')
vim.keymap.set('n', 'rn', ':EasyCompleteRename<CR>')
vim.keymap.set('n', 'gb', ':BackToOriginalBuffer<CR>')
Set trigger completion mapping:
let g:easycomplete_tab_trigger="<c-space>"
The plugin has already map diagnostic jumping to <C-n>
and <S-C-n>
. You can change these mapping via:
let g:easycomplete_diagnostics_next = "<C-J>"
let g:easycomplete_diagnostics_prev = "<C-k>"
- Set
let g:easycomplete_diagnostics_enable = 0
to disable lsp diagnostics. - Set
let g:easycomplete_lsp_checking = 0
to disable lsp checking for installation. - Set
let g:easycomplete_signature_enable = 0
to disable lsp signature checking.
Typing :h easycomplete
for help.
Language Support
It support keywords/dictionary/directory completion by default.
Semantic Completion for Other Languages
There are tow ways to install lsp server.
- For vim/nvim: via integrated installer by
:InstallLspServer
. - For nvim only: via nvim-lsp-installer by
:LspInstall
Plug 'williamboman/nvim-lsp-installer'
LSP Server will all be installed in ~/.config/vim-easycomplete/servers
.
You can give a specified plugin name for InstallLspServer
command. Both of the following useage are avilable:
:InstallLspServer
:InstallLspServer lua
All supported languages:
Plugin Name | Languages | Language Server | Installer | Requirements | nvim-lsp-installer support |
---|---|---|---|---|---|
directory | directory | No Need | Integrated | None | - |
buf | buf & dict | No Need | Integrated | None | - |
snips | Snippets | ultisnips | Integrated | python3 | - |
ts | js/ts | tsserver | Yes | node/npm | Yes |
deno | js/ts | denols | Yes | deno | Yes |
tn | TabNine | TabNine | Yes | None | No |
vim | Vim | vimls | Yes | node/npm | Yes |
cpp | C/C++/OC | clangd | Yes | None | Yes |
css | CSS | cssls | Yes | node/npm | Yes |
html | HTML | html | Yes | node/npm | Yes |
yml | YAML | yamlls | Yes | node/npm | Yes |
xml | Xml | lemminx | Yes | java/jdk | Yes |
sh | Bash | bashls | Yes | node/npm | Yes |
json | JSON | json-languageserver | Yes | node/npm | No |
php | php | intelephense | Yes | node/npm | Yes |
dart | dart | dartls | Yes | None | Yes |
py | Python | pylsp | Yes | python3/pip3 | Yes |
java | Java | jdtls | Yes | java11/jdk | Yes |
go | Go | gopls | Yes | go | Yes |
r | R | r-languageserver | Yes | R | No |
rb | Ruby | solargraph | Yes | ruby/bundle | No |
lua | Lua | sumneko_lua |
Yes | Lua | Yes |
nim | Nim | nimls | Yes | nim/nimble | Yes |
rust | Rust | rust_analyzer |
Yes | None | Yes |
kt | Kotlin | kotlin_language_server |
Yes | java/jdk | Yes |
grvy | Groovy | groovyls | Yes | java/jdk | Yes |
cmake | cmake | cmake | Yes | python3/pip3 | Yes |
c# | C# | omnisharp-lsp | Yes | None | No |
More info about semantic completion for each supported language:
- JavaScript & TypeScript: tsserver required.
- Python: pylsp required. (
pip install python-language-server
) - Go: gopls required. (
go get golang.org/x/tools/gopls
) - Vim Script: vimls required.
- C++/C/OC:Clangd required.
- CSS: cssls required. (css-languageserver),Css-languageserver dose not support CompletionProvider by default as it requires Snippets,You must install it manually.
- JSON: json-languageserver required.
- PHP: intelephense
- Dart: dartls
- HTML: html required. html-languageserver dose not support CompletionProvider by default. You must install Snippets manually.
- Shell: bashls required.
- Java: jdtls, java 11 and upper version required.
- Cmake: cmake required.
- Kotlin: kotlin_language_server required.
- Rust: rust-analyzer required.
- Lua: sumneko_lua required. Local configuration file path is
~/.config/vim-easycomplete/servers/lua/config.json
. Get more information here. - Xml: lemminx required.
- Groovy: groovyls required.
- Yaml: yamlls required.
- Ruby: solargraph required.
- Nim: nimlsp required. packages.json downloading is very slow, You'd better intall minlsp manually via
choosenim
follow this guide. - Deno: denols required. Use
:DenoCache
command fordeno cache
current ts/js file. - C# : omnisharp required.
- R: r-languageserver required.
- TabNine: TabNine
Add filetypes whitelist for specified language plugin:
let g:easycomplete_filetypes = {
\ "sh": {
\ "whitelist": ["shell"]
\ },
\ "r": {
\ "whitelist": ["rmd", "rmarkdown"]
\ },
\ }
Snippet Support
Vim-EasyComplete does not support snippets by default. If you want snippet integration, you will first have to install ultisnips
. UltiSnips is compatible with Vim-EasyComplete out of the box. UltiSnips required python3 installed.
Solution of "E319: No python3 provider found" Error in neovim 0.4.4 with ultisnips
TabNine Support
Install TabNine: :InstallLspServer tabnine
. Then restart your vim/nvim.
Set let g:easycomplete_tabnine_enable = 0
to disable TabNine. You can config TabNine by g:easycomplete_tabnine_config
witch contains two properties:
- line_limit: The number of lines before and after the cursor to send to TabNine. If the option is smaller, the performance may be improved. (default: 1000)
- max_num_result: Max results from TabNine. (default: 10)
let g:easycomplete_tabnine_config = {
\ 'line_limit': 1000,
\ 'max_num_result' : 10,
\ }
By default, an API key is not required to use TabNine in vim-easycomplete. If you have a Tabnine's Pro API key or purchased a subscription license. To configure, you'll need to use the TabNine' magic string. Type Tabnine::config
in insert mode to open the configuration panel.
Beautify the vim completion menu
There are four build-in popup menu themes in cterm: blue
,light
,rider
and sharp
(for iterm). (let g:easycomplete_scheme="sharp"
). Customise vim completion menu via these configurations:
If you just want to use default nerdfonts configuration, you can simplily config g:easycomplete_nerd_font
let g:easycomplete_nerd_font = 1
In most cases, the configuration "g:easycomplete_nerd_font = 1
" is already enough, but if you want to customize the kind icon, you can modify the configuration like this with https://nerdfonts.com installed:
let g:easycomplete_menu_skin = {
\ "buf": {
\ "kind":"⚯",
\ "menu":"[B]",
\ },
\ "snip": {
\ "kind":"<>",
\ "menu":"[S]",
\ },
\ "dict": {
\ "kind":"d",
\ "menu":"[D]",
\ },
\ "tabnine": {
\ "kind":"",
\ },
\ }
let g:easycomplete_lsp_type_font = {
\ 'text' : '⚯', 'method':'m', 'function': 'f',
\ 'constructor' : '≡', 'field': 'f', 'default':'d',
\ 'variable' : '𝘤', 'class':'c', 'interface': 'i',
\ 'module' : 'm', 'property': 'p', 'unit':'u',
\ 'value' : '𝘧', 'enum': 'e', 'keyword': 'k',
\ 'snippet': '𝘧', 'color': 'c', 'file':'f',
\ 'reference': 'r', 'folder': 'f', 'enummember': 'e',
\ 'constant':'c', 'struct': 's', 'event':'e',
\ 'typeparameter': 't', 'var': 'v', 'const': 'c',
\ 'operator':'o',
\ 't':'𝘵', 'f':'𝘧', 'c':'𝘤', 'm':'𝘮', 'u':'𝘶', 'e':'𝘦',
\ 's':'𝘴', 'v':'𝘷', 'i':'𝘪', 'p':'𝘱', 'k':'𝘬', 'r':'𝘳',
\ 'o':"𝘰", 'l':"𝘭", 'a':"𝘢", 'd':'𝘥',
\ }
Config error sign text:
let g:easycomplete_sign_text = {
\ 'error': "◉",
\ 'warning': "▲",
\ 'information': '◎',
\ 'hint': '▧'
\ }
You can define icon alias via giving fullnames and shortname.
Enable colorful styled menu (experimental):
let g:easycomplete_colorful = 1
Add custom completion plugin
→ add custom completion plugin
Issues
[WIP] If you have bug reports or feature suggestions, please use the issue tracker. In the meantime feel free to read some of my thoughts at https://zhuanlan.zhihu.com/p/366496399, https://zhuanlan.zhihu.com/p/425555993, https://medium.com/@lijing00333/vim-easycomplete
More Examples:
Update Deno Cache via :DenoCache
Directory selecting:
Handle backsapce typing
Snip Support
Diagnostics jumping
Signature
TabNine supporting:
License
MIT