Last active
September 1, 2024 11:18
-
-
Save junegunn/5dff641d68d20ba309ce to your computer and use it in GitHub Desktop.
Plugin completion using VimAwesome API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" ---------------------------------------------------------------------------- | |
" vimawesome.com | |
" ---------------------------------------------------------------------------- | |
function! VimAwesomeComplete() abort | |
let prefix = matchstr(strpart(getline('.'), 0, col('.') - 1), '[.a-zA-Z0-9_/-]*$') | |
echohl WarningMsg | |
echo 'Downloading plugin list from VimAwesome' | |
echohl None | |
ruby << EOF | |
require 'json' | |
require 'open-uri' | |
query = VIM::evaluate('prefix').gsub('/', '%20') | |
items = 1.upto(max_pages = 3).map do |page| | |
Thread.new do | |
url = "http://vimawesome.com/api/plugins?page=#{page}&query=#{query}" | |
data = open(url).read | |
json = JSON.parse(data, symbolize_names: true) | |
json[:plugins].map do |info| | |
pair = info.values_at :github_owner, :github_repo_name | |
next if pair.any? { |e| e.nil? || e.empty? } | |
{word: pair.join('/'), | |
menu: info[:category].to_s, | |
info: info.values_at(:short_desc, :author).compact.join($/)} | |
end.compact | |
end | |
end.each(&:join).map(&:value).inject(:+) | |
VIM::command("let cands = #{JSON.dump items}") | |
EOF | |
if !empty(cands) | |
inoremap <buffer> <c-v> <c-n> | |
augroup _VimAwesomeComplete | |
autocmd! | |
autocmd CursorMovedI,InsertLeave * iunmap <buffer> <c-v> | |
\| autocmd! _VimAwesomeComplete | |
augroup END | |
call complete(col('.') - strchars(prefix), cands) | |
endif | |
return '' | |
endfunction | |
augroup VimAwesomeComplete | |
autocmd! | |
autocmd FileType vim inoremap <c-x><c-v> <c-r>=VimAwesomeComplete()<cr> | |
augroup END |
I'm using your script and gvim on Windows shows message:
[vim-plug] vim - Invalid argument: vim - (implicit
vim-scripts
expansion is deprecated)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@junegunn, when I tried using this, it was failing for me with some
Open.uri from kernel is deprecated
. I did a little bit of searching and fixed it by only usingURI.open(URL)
instead ofopen(URL)
.Here is the updated code: