open-browser.vim icon indicating copy to clipboard operation
open-browser.vim copied to clipboard

Is it possible to open URL for junegunn/vim-plug Plug keyword?

Open dracorp opened this issue 6 years ago • 3 comments

Hi Is it possible to configure open-browser.vim plugin to open the URL for vim-plug Plug keyword? For example gx on line with:

Plug 'tyru/open-browser.vim'

opens https://github.com/tyru/open-browser.vim URL.

How do you configure the plugin to support a keyword Plug, or any other, with a space and convert it to the right URL?

dracorp avatar May 19 '19 12:05 dracorp

I don't know whether that's possible, but what I do instead is specify the full URL since Plug can handle that fine:

Plug 'https://github.com/tyru/open-browser.vim'

Now I can open the GitHub repo using gx.

mb720 avatar Jul 27 '19 08:07 mb720

Thx for pointing. It seems best solution at now.

dracorp avatar Oct 05 '19 12:10 dracorp

This is what I'm doing for now:

vnoremap gx :<C-U>call <SID>my_smart_search()<CR>

fun! s:my_smart_search()"{{{
    let l:selection = s:get_visual_selection(visualmode(), 1)

    let l:result = matchlist(l:selection, "^Plug\\s'\\([^']\\+\\)'.*$")
    if len(l:result) > 2
        let l:plugin_name = l:result[1]
        exe 'OpenBrowser https://github.com/' . l:plugin_name
        return
    endif

    exe 'OpenBrowserSmartSearch ' . l:selection
endfun"}}}

fun! s:get_visual_selection(type, ...)"{{{
    let sel_save   = &selection
    let &selection = 'inclusive'
    let reg_save   = @@

    if a:0
        silent exe 'normal! `<' . a:type . '`>y'
    elseif a:type ==? 'line'
        silent exe "normal! '[V']y"
    elseif a:type ==? 'block'
        silent exe 'normal! `[\<C-V>`]y'
    else
        silent exe 'normal! `[v`]y'
    endif

    let l:selection = @@

    let &selection = sel_save
    let @@ = reg_save

    return l:selection
endfun"}}}

xbot avatar Sep 04 '22 02:09 xbot