Open URL under cursor in Vim with browser

后端 未结 11 997
一整个雨季
一整个雨季 2021-01-29 20:05

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

11条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-29 20:50

    Updated: from tpope's tweet today

    Press gx. You can customize the browser. On Gnome and Mac OS X it's already use gnome-open/open. Generally you can set g:netrw_browsex_viewer to anything you want.


    Original answer:

    Don't remember where I get this function. There is a bug with hash (#) in the url, but the function works well enough that I won't bother fixing it.

    function! HandleURL()
      let s:uri = matchstr(getline("."), '[a-z]*:\/\/[^ >,;]*')
      echo s:uri
      if s:uri != ""
        silent exec "!open '".s:uri."'"
      else
        echo "No URI found in line."
      endif
    endfunction
    map u :call HandleURL()
    

    Note: If you are not on the Mac, use gnome-open/xdg-open for Linux, or 'path to your web browser' for Windows

提交回复
热议问题