• Stars
    star
    893
  • Rank 51,128 (Top 2 %)
  • Language
    Vim Script
  • License
    MIT License
  • Created almost 8 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

async completion in pure vim script for vim8 and neovim

asyncomplete.vim

Async autocompletion for Vim 8 and Neovim with |timers|.

This is inspired by nvim-complete-manager but written in pure Vim Script.

Installing

Plug 'prabirshrestha/asyncomplete.vim'

Tab completion

inoremap <expr> <Tab>   pumvisible() ? "\<C-n>" : "\<Tab>"
inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"
inoremap <expr> <cr>    pumvisible() ? asyncomplete#close_popup() : "\<cr>"

If you prefer the enter key to always insert a new line (even if the popup menu is visible) then you can amend the above mapping as follows:

inoremap <expr> <cr> pumvisible() ? asyncomplete#close_popup() . "\<cr>" : "\<cr>"

Force refresh completion

imap <c-space> <Plug>(asyncomplete_force_refresh)
" For Vim 8 (<c-@> corresponds to <c-space>):
" imap <c-@> <Plug>(asyncomplete_force_refresh)

Auto popup

By default asyncomplete will automatically show the autocomplete popup menu as you start typing. If you would like to disable the default behavior set g:asyncomplete_auto_popup to 0.

let g:asyncomplete_auto_popup = 0

You can use the above <Plug>(asyncomplete_force_refresh) to show the popup or you can tab to show the autocomplete.

let g:asyncomplete_auto_popup = 0

function! s:check_back_space() abort
    let col = col('.') - 1
    return !col || getline('.')[col - 1]  =~ '\s'
endfunction

inoremap <silent><expr> <TAB>
  \ pumvisible() ? "\<C-n>" :
  \ <SID>check_back_space() ? "\<TAB>" :
  \ asyncomplete#force_refresh()
inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"

Preview Window

To enable preview window:

" allow modifying the completeopt variable, or it will
" be overridden all the time
let g:asyncomplete_auto_completeopt = 0

set completeopt=menuone,noinsert,noselect,preview

To auto close preview window when completion is done.

autocmd! CompleteDone * if pumvisible() == 0 | pclose | endif

Sources

asyncomplete.vim deliberately does not contain any sources. Please use one of the following sources or create your own.

Language Server Protocol (LSP)

Language Server Protocol via vim-lsp and asyncomplete-lsp.vim

Please note that vim-lsp setup for neovim requires neovim v0.2.0 or higher, since it uses lambda setup.

Plug 'prabirshrestha/asyncomplete.vim'
Plug 'prabirshrestha/vim-lsp'
Plug 'prabirshrestha/asyncomplete-lsp.vim'

if executable('pyls')
    " pip install python-language-server
    au User lsp_setup call lsp#register_server({
        \ 'name': 'pyls',
        \ 'cmd': {server_info->['pyls']},
        \ 'allowlist': ['python'],
        \ })
endif

Refer to vim-lsp wiki for configuring other language servers. Besides auto-complete language server support other features such as go to definition, find references, renaming symbols, document symbols, find workspace symbols, formatting and so on.

in alphabetical order

Languages/FileType/Source Links
Ale asyncomplete-ale.vim
Buffer asyncomplete-buffer.vim
C/C++ asyncomplete-clang.vim
Clojure async-clj-omni
Common Lisp (vlime) vlime
Dictionary (look) asyncomplete-look
Emmet asyncomplete-emmet.vim
English asyncomplete-nextword.vim
Emoji asyncomplete-emoji.vim
Filenames / directories asyncomplete-file.vim
NeoInclude asyncomplete-neoinclude.vim
Go asyncomplete-gocode.vim
Git commit message asyncomplete-gitcommit
JavaScript (Flow) asyncomplete-flow.vim
Neosnippet asyncomplete-neosnippet.vim
Omni asyncomplete-omni.vim
PivotalTracker stories asyncomplete-pivotaltracker.vim
Rust (racer) asyncomplete-racer.vim
TabNine powered by AI asyncomplete-tabnine.vim
tmux complete tmux-complete.vim
Typescript asyncomplete-tscompletejob.vim
UltiSnips asyncomplete-ultisnips.vim
User (compl-function) asyncomplete-user.vim
Vim Syntax asyncomplete-necosyntax.vim
Vim tags asyncomplete-tags.vim
Vim asyncomplete-necovim.vim

can't find what you are looking for? write one instead an send a PR to be included here or search github topics tagged with asyncomplete at https://github.com/topics/asyncomplete.

Using existing vim plugin sources

Rather than writing your own completion source from scratch you could also suggests other plugin authors to provide a async completion api that works for asyncomplete.vim or any other async autocomplete libraries without taking a dependency on asyncomplete.vim. The plugin can provide a function that takes a callback which returns the list of candidates and the startcol from where it must show the popup. Candidates can be list of words or vim's complete-items.

function s:completor(opt, ctx)
  call mylanguage#get_async_completions({candidates, startcol -> asyncomplete#complete(a:opt['name'], a:ctx, startcol, candidates) })
endfunction

au User asyncomplete_setup call asyncomplete#register_source({
    \ 'name': 'mylanguage',
    \ 'allowlist': ['*'],
    \ 'completor': function('s:completor'),
    \ })

Example

function! s:js_completor(opt, ctx) abort
    let l:col = a:ctx['col']
    let l:typed = a:ctx['typed']

    let l:kw = matchstr(l:typed, '\v\S+$')
    let l:kwlen = len(l:kw)

    let l:startcol = l:col - l:kwlen

    let l:matches = [
        \ "do", "if", "in", "for", "let", "new", "try", "var", "case", "else", "enum", "eval", "null", "this", "true",
        \ "void", "with", "await", "break", "catch", "class", "const", "false", "super", "throw", "while", "yield",
        \ "delete", "export", "import", "public", "return", "static", "switch", "typeof", "default", "extends",
        \ "finally", "package", "private", "continue", "debugger", "function", "arguments", "interface", "protected",
        \ "implements", "instanceof"
        \ ]

    call asyncomplete#complete(a:opt['name'], a:ctx, l:startcol, l:matches)
endfunction

au User asyncomplete_setup call asyncomplete#register_source({
    \ 'name': 'javascript',
    \ 'allowlist': ['javascript'],
    \ 'completor': function('s:js_completor'),
    \ })

The above sample shows synchronous completion. If you would like to make it async just call asyncomplete#complete whenever you have the results ready.

call timer_start(2000, {timer-> asyncomplete#complete(a:opt['name'], a:ctx, l:startcol, l:matches)})

If you are returning incomplete results and would like to trigger completion on the next keypress pass 1 as the fifth parameter to asyncomplete#complete which signifies the result is incomplete.

call asyncomplete#complete(a:opt['name'], a:ctx, l:startcol, l:matches, 1)

As a source author you do not have to worry about synchronization issues in case the server returns the async completion after the user has typed more characters. asyncomplete.vim uses partial caching as well as ignores if the context changes when calling asyncomplete#complete. This is one of the core reason why the original context must be passed when calling asyncomplete#complete.

Credits

All the credit goes to the following projects

Contributors

Code Contributors

This project exists thanks to all the people who contribute. [Contribute].

Financial Contributors

Become a financial contributor and help us sustain our community. [Contribute]

Individuals

Organizations

Support this project with your organization. Your logo will show up here with a link to your website. [Contribute]

More Repositories

1

vim-lsp

async language server protocol plugin for vim and neovim
Vim Script
3,098
star
2

dwm-win32

dwm port of tiling manager to Window
C
439
star
3

async.vim

normalize async job control api for vim and neovim
Vim Script
275
star
4

asyncomplete-lsp.vim

Vim Script
122
star
5

hn-react

Hacker News Client built using ReactJS
JavaScript
119
star
6

quickpick.vim

experimental quick picker for vim
Vim Script
79
star
7

FluentHttp

a light weight library aimed to ease the development for your rest client
C#
48
star
8

dotfiles

There is no place like ~
Lua
48
star
9

asyncomplete-buffer.vim

provides buffer autocomplete for asyncomplete.vim
Vim Script
43
star
10

reactive-cocoa-playground

Objective-C
40
star
11

asyncomplete-file.vim

provides file autocomplete for asyncomplete.vim
Vim Script
39
star
12

rblog

super fast blog engine written in rust. live demo @ https://blog.prabir.me
Rust
36
star
13

asyncomplete-ultisnips.vim

provides ultisnips autocomplete for asyncomplete.vim
Vim Script
33
star
14

FacebookSharp

Facebook Graph API for .Net
C#
30
star
15

callbag.vim

Vim Script
27
star
16

typescript-language-server

Language Server Protocol implementation for Typescript via tsserver
TypeScript
25
star
17

asyncomplete-tags.vim

provides tag auto completion for asyncomplete.vim via vim tagfiles
Vim Script
23
star
18

simple-ubuntu-installer

simple encrypted zfs ubuntu installer
Shell
22
star
19

simple-arch-installer

Shell
19
star
20

synology-nomad

Shell
19
star
21

FB-CSharp-SDK-First-FB-Application

Facebook C# SDK - Writing your first facebook application
C#
19
star
22

asyncomplete-gocode.vim

provides go autocomplete for asyncomplete.vim via gocode
Vim Script
18
star
23

nji

NodeJs (Package) Installer
C#
17
star
24

async-vfs

async vfs for rust
Rust
13
star
25

asyncomplete-flow.vim

provides javascript autocomplete for asyncomplete.vim via flow
Vim Script
13
star
26

asyncomplete-necovim.vim

provides syntax autocomplete for asyncomplete.vim via neco-vim
Vim Script
13
star
27

writing-an-os-from-scratch

This is a tutorial that teaches you how to write a bootloader/os from scratch
Assembly
12
star
28

simple-owin

simple owin implementation examples
C#
12
star
29

mq

Rust
11
star
30

asyncomplete-emoji.vim

provides emoji autocomplete for asyncomplete.vim
Vim Script
10
star
31

njake

node.js jakefile helper tasks for .net developers
JavaScript
10
star
32

asyncomplete-neosnippet.vim

provides neosnippet autocomplete for asyncomplete.vim
Vim Script
10
star
33

quickpick-colorschemes.vim

Colorscheme picker for quickpick.vim
Vim Script
10
star
34

asyncomplete-tscompletejob.vim

provides typescript autocomplete for asyncomplete.vim via tscompletejob
Vim Script
9
star
35

lua-callbag

Lua
8
star
36

surrealdb-migrator

Rust
8
star
37

nuget-button

javascript helper for generating nuget button
JavaScript
8
star
38

lua-eventbus

Lua
8
star
39

writing-vim-plugins-in-lua

7
star
40

asyncomplete-emmet.vim

Vim Script
6
star
41

asyncomplete-necosyntax.vim

provides syntax autocomplete for asyncomplete.vim via necosyntax
Vim Script
6
star
42

win32-c-boilerplate

boilerplate code for win32 c binaries
Makefile
6
star
43

universal-typescript-boilerplate

TypeScript
5
star
44

Facebook.Extensions.Task

C# v5 async extensions for Facebook C# SDK
C#
5
star
45

gitignore

common gitignore files for .net development
5
star
46

opengraph.net

C# Facebook OpenGraph.NET library fork from http://opengraph.codeplex.com
C#
5
star
47

rax

middleware for .net (trying to make owin better)
C#
4
star
48

quickpick-lsp.vim

Vim Script
4
star
49

sprockets-dotnet

Sprockets style dependency resolver for .NET
JavaScript
4
star
50

dark-themes

Dark themes for various text editors - Visual Studio, Notepad++, Vim, Eclipse
Vim Script
4
star
51

Facebook.Moq

Moq helpers for Facebook C# SDK
C#
4
star
52

linqtofacebook

Linq Provider for Facebook Graph API
C#
4
star
53

typescript-webpack-umd-boilerplate

JavaScript
4
star
54

NancyFacebookSample

NancyFx + Facebook C# SDK
C#
4
star
55

winzsh

Fork of https://sourceforge.net/projects/zsh-nt/
C
4
star
56

azure-sdk-for-net-tasks

TPL extensions for Azure SDK for .NET
C#
4
star
57

quickpick-npm.vim

Vim Script
3
star
58

dwm-win32-6

C
3
star
59

ProfilesAndSettings

Stores my profile and settings for PowerShell, gitconfig, hgrc, irbc
Vim Script
3
star
60

hn-react-mobx

HackerNews + MobX + React
JavaScript
3
star
61

socket-io-net

socket.io server implemented in .net and owin
JavaScript
3
star
62

github

github api wrapper for .net
C#
3
star
63

SimpleFx

SimpleFX is a list of .NET libraries that match the Simple ethos and does its job well.
3
star
64

backbone-js-on-nancy

Sample demonstrating Single Page App using Backbone JS and NancyFX
JavaScript
3
star
65

vs-erc

C#
3
star
66

synology-package-template

Shell
3
star
67

ctrlp-env

ctrlp extension to view environment variables
Vim Script
2
star
68

Unity.Wcf

unity di for wcf
C#
2
star
69

js-namespace

Javscript Namespace Library
JavaScript
2
star
70

wilo

Rust
2
star
71

zcloud

Shell
2
star
72

moonrepo-rust-vite-template

CSS
2
star
73

vim-fz-extras

Vim Script
2
star
74

go-coreutils

coreutils written in go
Go
2
star
75

tsearch

Rust
2
star
76

quickpick-filetypes.vim

filetype picker for quickpick.vim
Vim Script
2
star
77

vsnip-snippets

My snippets for https://github.com/hrsh7th/vim-vsnip
2
star
78

my-sublimetext-settings

My Sublime Text 2 settings for Mac and Windows
2
star
79

reactjs-typescript-boilerplate

JavaScript
2
star
80

trillium-send-file

Rust
1
star
81

expressjs-boilerplate

expressjs/backbone boilerplate
JavaScript
1
star
82

dwmjs

C
1
star
83

cowsay.rs

Rust
1
star
84

hapijs-sample

JavaScript
1
star
85

my-node-playground

JavaScript
1
star
86

Prabir.CocoR

Coco/R plugin for Visual Studio
C#
1
star
87

TaskExtensions

Helper Extensions methods for Task Parallel Library
C#
1
star
88

NuGetPowerShellScripts

helpers powershell scripts for nuget
1
star
89

salvo-template

Rust
1
star
90

ELMAH.MySql

MySql provider for ELMAH
1
star
91

docker-static-site

HTML
1
star
92

vfs-s3

Amazon S3 backend for @c9/vfs
JavaScript
1
star
93

StyleCopCmd

Fork of StyleCopCmd from http://nichesoftware.co.nz/page/373/stylecop-cmd-version-history
Ruby
1
star
94

Nancy.Facebook.RealtimeSubscription

C#
1
star
95

objstor

object store
Rust
1
star
96

reactjs-boilerplate

ReactJS boilerplate code with WebPack
JavaScript
1
star
97

dotnet-in-python

C#
1
star
98

SimpleBlog

Simple .NET Blog written in OWIN
C#
1
star
99

python-sdk

This SDK is deprecated. It does not support the new cookie format that we rolled out as part of the OAuth Migration. In short, it doesn't work. We currently have no plans to update it. Feel free to clone this repository and modify.
Python
1
star