Humanity

Edit the world by your favorite way

open-browser.vim, urilib.vim

という2つのプラグインを作った。

tyru/open-browser.vim · GitHub
tyru/urilib.vim · GitHub

nmap hoge <Plug>(openbrowser-open)
vmap hoge <Plug>(openbrowser-open)

とかやればhogeでカーソル下のURLを開いてくれます。
visual modeでもhogeとやれば選択してるURLを開いてくれます。

また「ttp://〜」なURLもurilib.vimというライブラリを入れることでhttpとして開くことができるようになります。
詳しく言うと、urilib.vimというライブラリがインストールされていれば
URLのパースを行ってg:openbrowser_fix_schemesというグローバル変数
指定されてるようにschemeの変換をしてくれます。


urilib.vimPerlURI.pmにインスパイアされた作りになっていて、

try
    let uri = urilib#new('http://twitter.com/tyru')
    " httpと表示
    echo uri.scheme
    " twitter.comと表示
    echo uri.host
    " tyruと表示
    echo uri.path
catch /^uri parse error:/
    echoerr v:exception
catch /^not valid uri::/
    echoerr v:exception
endtry

もしくは

let uri = urilib#new_no_throw('http://twitter.com/tyru', -1)
if type(uri) == type(-1)
    echoerr v:exception
endif

" httpと表示
echo uri.scheme
" twitter.comと表示
echo uri.host
" tyruと表示
echo uri.path

という風に扱えます。



追記:
最新版ではurilib#new_no_throw()は削除されました。
urilib.vimについてはまた後で書きます。