Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

async completion in pure vim script for vim8 and neovim

License

NotificationsYou must be signed in to change notification settings

prabirshrestha/asyncomplete.vim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

This is inspired bynvim-complete-manager but writtenin 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) thenyou 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 setg:asyncomplete_auto_popup to 0.

letg:asyncomplete_auto_popup=0

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

letg:asyncomplete_auto_popup=0function!s:check_back_space()abortletcol=col('.')-1return!col||getline('.')[col-1]=~'\s'endfunctioninoremap<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 timeletg:asyncomplete_auto_completeopt=0setcompleteopt=menuone,noinsert,noselect,preview

To auto close preview window when completion is done.

autocmd!CompleteDone*ifpumvisible()==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 viavim-lsp andasyncomplete-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'ifexecutable('pyls')" pip install python-language-serverauUserlsp_setupcalllsp#register_server({\'name':'pyls',\'cmd': {server_info->['pyls']},\'allowlist': ['python'],\})endif

Refer tovim-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/SourceLinks
Aleasyncomplete-ale.vim
Bufferasyncomplete-buffer.vim
C/C++asyncomplete-clang.vim
Clojureasync-clj-omni
Common Lisp (vlime)vlime
Dictionary (look)asyncomplete-look
Emmetasyncomplete-emmet.vim
Englishasyncomplete-nextword.vim
Emojiasyncomplete-emoji.vim
Filenames / directoriesasyncomplete-file.vim
NeoIncludeasyncomplete-neoinclude.vim
Goasyncomplete-gocode.vim
Git commit messageasyncomplete-gitcommit
JavaScript (Flow)asyncomplete-flow.vim
Neosnippetasyncomplete-neosnippet.vim
Omniasyncomplete-omni.vim
PivotalTracker storiesasyncomplete-pivotaltracker.vim
Rust (racer)asyncomplete-racer.vim
TabNine powered by AIasyncomplete-tabnine.vim
tmux completetmux-complete.vim
Typescriptasyncomplete-tscompletejob.vim
UltiSnipsasyncomplete-ultisnips.vim
User (compl-function)asyncomplete-user.vim
Vim Syntaxasyncomplete-necosyntax.vim
Vim tagsasyncomplete-tags.vim
Vimasyncomplete-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 athttps://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'scomplete-items.

functions:completor(opt, ctx)callmylanguage#get_async_completions({candidates, startcol->asyncomplete#complete(a:opt['name'],a:ctx, startcol, candidates) })endfunctionauUserasyncomplete_setupcallasyncomplete#register_source({\'name':'mylanguage',\'allowlist': ['*'],\'completor':function('s:completor'),\})

Example

function!s:js_completor(opt, ctx)abortletl:col=a:ctx['col']letl:typed=a:ctx['typed']letl:kw=matchstr(l:typed,'\v\S+$')letl:kwlen=len(l:kw)letl:startcol=l:col-l:kwlenletl: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"\]callasyncomplete#complete(a:opt['name'],a:ctx,l:startcol,l:matches)endfunctionauUserasyncomplete_setupcallasyncomplete#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 callasyncomplete#complete whenever you have the results ready.

calltimer_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 pass1 as the fifth parameter toasyncomplete#completewhich signifies the result is incomplete.

callasyncomplete#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 morecharacters. asyncomplete.vim uses partial caching as well as ignores if the context changes when callingasyncomplete#complete.This is one of the core reason why the original context must be passed when callingasyncomplete#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]

About

async completion in pure vim script for vim8 and neovim

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

    Packages

    No packages published

    [8]ページ先頭

    ©2009-2025 Movatter.jp