Skip to content

Instantly share code, notes, and snippets.

@lf-wxp
Forked from junegunn/vimawesome.vim
Created February 28, 2018 07:54
Show Gist options
  • Select an option

  • Save lf-wxp/4c849fc4351b7aa7aeb764a5170bd2a8 to your computer and use it in GitHub Desktop.

Select an option

Save lf-wxp/4c849fc4351b7aa7aeb764a5170bd2a8 to your computer and use it in GitHub Desktop.

Revisions

  1. @junegunn junegunn renamed this gist May 22, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. @junegunn junegunn revised this gist May 16, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.vim
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@
    " vimawesome.com
    " ----------------------------------------------------------------------------
    function! VimAwesomeComplete() abort
    let prefix = matchstr(strpart(getline('.'), 0, col('.') - 1), '[a-zA-Z0-9_/-]*$')
    let prefix = matchstr(strpart(getline('.'), 0, col('.') - 1), '[.a-zA-Z0-9_/-]*$')
    echohl WarningMsg
    echo 'Downloading plugin list from VimAwesome'
    echohl None
  3. @junegunn junegunn revised this gist May 16, 2015. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions gistfile1.vim
    Original file line number Diff line number Diff line change
    @@ -13,9 +13,9 @@ ruby << EOF
    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)
    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? }
  4. @junegunn junegunn created this gist May 15, 2015.
    46 changes: 46 additions & 0 deletions gistfile1.vim
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,46 @@
    " ----------------------------------------------------------------------------
    " 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