open-browser.vim
open-browser.vim copied to clipboard
Is it possible to open URL for junegunn/vim-plug Plug keyword?
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?
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.
Thx for pointing. It seems best solution at now.
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"}}}