Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Plugin completion using VimAwesome API
" ----------------------------------------------------------------------------
" 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
@junegunn
Owner

@nightire

Love you man~

@starcraftman

Very cool. You at all interested in putting that into plug.vim to toggle on? Though it might be a bit more useful as a perhaps a search command in left pane? If not, we can at least put this in the wiki faq I guess.

@junegunn
Owner

@starcraftman Well, I'd like to avoid making vim-plug dependent on external services, and the result of VimAwesome API doesn't seem flawless; missing plugins, duplicate results, etc. Moreover, I'm not convinced if the site is being actively maintained: vim-awesome/vim-awesome#61

Yeah, we should put this on the wiki page (a link on "Home" page or maybe a separate page?) since this compensates for the missing :PluginSearch from Vundle.

@starcraftman

@junegunn Ah damn, seems their main dev(s) got busy. Should probably give em a hand, do love that site. The duping problem is a real bummer.

Separately, have you ruled out ever adding PlugSearch or just didn't because vim.org wasn't great to search against?

@junegunn
Owner

@starcraftman In my opinion, vim.org no longer functions as the central repository. I don't even publish my plugins there anymore. Regarding the command, I know that some people want PluginSearch equivalent in vim-plug, but I personally don't see the point of it. Don't we all have web browsers? :) Also I don't think it has to be a part of vim-plug, it can be a separate plugin.

@junegunn
Owner

Yeah, I think it should be a plugin of its own, doesn't have to be limited to a specific plugin manager.

@starcraftman

@junegunn I guess your right. Separate plugin makes most sense, searching isn't really part of plugin management.

Do hope VimAwesome isn't abandoned. Only just realized Gundo hadn't gotten a patch in a year. Sad when good software falls by wayside. :/

@mhinz
mhinz commented May 16, 2015

@junegunn Neat! :-)

@starcraftman If it's still working for you, by all means, keep it. Otherwise I enjoy using https://github.com/mbbill/undotree

@jonafato

VimAwesome isn't dead, though the main developer (@divad12) does seem to be busy. There was a bit of activity a couple of months ago, and he was quick to respond to pull requests. I can't speak for the project or its maintainers, but I'd guess that pull requests would be well received based on my limited experience with it.

@craigp
craigp commented May 18, 2015

This is epic

@mirzalazuardi

where should i put the file (vimawesome.vim) in case to combine with my vundle ?
is there a README.md for installing this ?

u're awesome dude!!

@junegunn
Owner

@mirzalazuardi Place the file in ~/.vim/plugin directory or simply paste the code onto your .vimrc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment