Open URL under cursor in Vim with browser

2020-05-11 03:09发布

I'm using Twitvim for the first time. Seeing all the URLs in there made me wonder, is there any way to open the URL under the cursor in your favorite browser or a specified one?

标签: vim
10条回答
Root(大扎)
2楼-- · 2020-05-11 03:44

You should take a quick look to this vim plugin

henrik/vim-open-url

It's basically what has been explained in some other responses, but specific configuration needed if you use a plugin manager :)

查看更多
神经病院院长
3楼-- · 2020-05-11 03:49

This is simple, just replace "start" with whatever your OS uses

GU for go url!

" Open url
if (has('win32') || has('win64'))
   nmap gu :exec "!start <cWORD>"<cr> 
else
   nmap gu :exec "!open <cWORD>"<cr> 
endif
查看更多
贼婆χ
4楼-- · 2020-05-11 03:50

If you are using Vim 7.4 or later, in normal mode, put your cursor below the URL, then click gx, the URL will be opened in browser automatic demo operate

查看更多
姐就是有狂的资本
5楼-- · 2020-05-11 03:57

Ok so using the answers from @tungd and @kev and a little research I ended up with this script, which works just the way I need to. Like @tungd said the # can give a problem if inside a url but I'm cool with that, if anyone has a better expression for the url then it will be welcomed.

function! OpenUrlUnderCursor()
    let path="/Applications/Safari.app"
    execute "normal BvEy"
    let url=matchstr(@0, '[a-z]*:\/\/[^ >,;]*')
    if url != ""
        silent exec "!open -a ".path." '".url."'" | redraw! 
        echo "opened ".url
    else
        echo "No URL under cursor."
    endif
endfunction
nmap <leader>o :call OpenUrlUnderCursor()<CR>
查看更多
登录 后发表回答