Skip to content

jayli/vim-easycomplete

Repository files navigation

Vim-EasyComplete

It's a Fast and Minimalism Style Completion Plugin for vim/nvim.

What

Vim-easycomplete is a fast and minimalism style completion plugin for both vim and nvim. It aims to be available out of the box on linux and mac. It is implemented in pure VimScript and is extremely simple to configure without installing Node and a bunch of Node modules. Thank nvim-cmp and coc.nvim. They inspired me a lot.

vim-easycomplete.mp4.mov

It contains these features:

  • Full lsp support. Easy to install LSP Server with one command
  • Keywords/Directory support
  • Implemented based on pure vimscript
  • Snippet support via Snippets.
  • Fast performance
  • AI coding assistant via tabnine.

Installation

Requires Vim 8.2 or higher version on MacOS/Linux/FreeBSD. Neovim 0.6.0 or higher.

Lua config with Packer.nvim:

use { 'jayli/vim-easycomplete', requires = {'SirVer/ultisnips'}}
-- Tabnine aicoding support, default is 1
-- You should install tabnine first by ":InstallLspServer tabnine"
vim.g.easycomplete_tabnine_enable = 1
-- Tabnine coding suggestion, default is 1
vim.g.easycomplete_tabnine_suggestion = 1
-- Using nerdfont for lsp icons, default is 0
vim.g.easycomplete_nerd_font = 1
-- Add window border for pum, default is 1 (for nvim 0.11 or higher)
vim.g.easycomplete_winborder = 1
-- Pmenu format, default is {"abbr", "kind", "menu"}
vim.g.easycomplete_pum_format = {"kind", "abbr", "menu"}
-- Useful keymap
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>')

Run :PackerInstall

Vimscript config with vim-plug:

Plug 'jayli/vim-easycomplete'
Plug 'SirVer/ultisnips'
" Tabnine aicoding support, default is 1
" You should install tabnine first by ":InstallLspServer tabnine"
let g:easycomplete_tabnine_enable = 1
" Tabnine coding suggestion, default is 1
let g:easycomplete_tabnine_suggestion = 1
" Using nerdfont for lsp icons, default is 0
let g:easycomplete_nerd_font = 1
" Add window border for pum, default is 1 (for nvim 0.11 or higher)
let g:easycomplete_winborder = 1
" Pmenu format, default is ["abbr", "kind", "menu"]
let g:easycomplete_pum_format = ["kind", "abbr", "menu"]
" Useful keymap
noremap gr :EasyCompleteReference<CR>
noremap gd :EasyCompleteGotoDefinition<CR>
noremap rn :EasyCompleteRename<CR>
noremap gb :BackToOriginalBuffer<CR>

Run :PlugInstall.

Full configuration example.

Useage

Use Tab to trigger the completion suggestions and select matched items. Use Ctrl-] for definition jumping, Ctrl-t for jumping back (Same as tags jumping).

Use Ctrl-N/Shift-Ctrl-N to jump to the next/previous diagnostic position.

Other optional configurations:

  • set updatetime=150 (lua: vim.opt.updatetime = 150) is highly recommended.
  • Menu noselected by default: setlocal completeopt+=noselect, (lua: vim.cmd('setlocal completeopt+=noselect'))

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

Global configurations:

Global Configure Default Description
g:easycomplete_nerd_font 0 Using nerdfont for lsp icons
g:easycomplete_menu_skin {} Menu skin.
g:easycomplete_sign_text {} Sign icons.
g:easycomplete_lsp_type_font ... lsp icons configuration
g:easycomplete_tabnine_suggestion 1 Tabnine inline suggestion(for nvim only)
g:easycomplete_lsp_checking 1 Check whether the lsp is installed while opening a file
g:easycomplete_tabnine_enable 1 Enable Tabnine
g:easycomplete_directory_enable 1 Directory complete
g:easycomplete_tabnine_config {} TabNine Configuration
g:easycomplete_filetypes {} Custom filetyps configuration
g:easycomplete_enable 1 Enable this plugin
g:easycomplete_tab_trigger <Tab> Use tab to trigger completion and select next item
g:easycomplete_shift_tab_trigger <S-Tab> Use s-tab to select previous item
g:easycomplete_cursor_word_hl 0 Highlight the symbol when holding the cursor
g:easycomplete_signature_offset 0 Signature offset
g:easycomplete_diagnostics_next <C-N> Goto next diagnostic position
g:easycomplete_diagnostics_prev <S-C-n> Goto previous diagnostic position
g:easycomplete_diagnostics_enable 1 Enable diagnostics
g:easycomplete_signature_enable 1 Enable signature
g:easycomplete_diagnostics_hover 1 Gives a diagnostic prompt when the cursor holds
g:easycomplete_winborder 1 Add window border for pum (for nvim 0.11 or higher)
g:easycomplete_pum_format ["abbr", "kind", "menu"] Pmenu format

Typing :h easycomplete for help.

Language Support

There are tow ways to install lsp server.

  1. For vim/nvim: use command:InstallLspServer.
  2. For nvim only: use nvim-lsp-installer by :LspInstall

LSP Server will all be installed in local path: ~/.config/vim-easycomplete/servers.

You can give a specified plugin name for InstallLspServer command. Both of the following useage are ok:

  • :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 supported language:

You can add filetypes whitelist for specified language plugin. In most cases, it is not necessary to do so:

let g:easycomplete_filetypes = {
      \   "sh": {
      \     "whitelist": ["shell"]
      \   },
      \   "r": {
      \     "whitelist": ["rmd", "rmarkdown"]
      \   },
      \ }

Snippet Support

Vim-EasyComplete does not integration snippets by default. If you want snippet support, please install ultisnips. UltiSnips is compatible with Vim-EasyComplete. UltiSnips required python3 installed.

Solution of "E319: No python3 provider found" Error in neovim 0.4.4 with ultisnips

AI Coding via 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: 3)
let g:easycomplete_tabnine_config = {
    \ 'line_limit': 1000,
    \ 'max_num_result' : 3,
    \ }

TabNine works well without APIKey. 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.

Disable TabNine inline suggestion: let g:easycomplete_tabnine_suggestion = 0.


Beautify completion menu

Set g:easycomplete_nerd_font = 1 to enable default nerdfonts configuration.

If you want to customize the kind icon, you can modify the configuration with https://nerdfonts.com installed. Examples.

You can add custom Pmenu styles by defining these highlight groups:

  • EasyFuzzyMatch: highlight fuzzy matching character. It links to "Constant" by default if it's not defined.
  • EasyPmenu: Pmenu style. It links to "Pmenu" by default.
  • EasyPmenuKind: PmenuKind style. It links to "PmenuKind" by default.
  • EasyPmenuExtra: PmenuExtra style. It links to "PmenuExtra" by default.
  • EasyFunction: Function kind icon style. links to "Conditional" by default.
  • EasySnippet: Snippet kind icon style. links to "Keyword" by default.
  • EasyTabNine: TabNine kind icon style. links to "Character" by default.
  • EasySnippets: TabNine snippets suggestion style. links to "LineNr" by default

When g:easycomplete_winborder is set to 1. The guibg of Pmenu will be set to be the same as the Normal guibg.

More examples here: full config example

截屏2023-12-30 20 25 06

Add custom completion plugin

add custom completion plugin

More Examples:

TabNine snippets inline suggestion

Update Deno Cache via :DenoCache

Directory selecting:

Handle backsapce typing

Snip Support

Diagnostics jumping

Signature

TabNine supporting:

License

MIT