Open URL under cursor in Vim with browser

后端 未结 11 1002
一整个雨季
一整个雨季 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:57

    This is a sort of improved version of the script originally proposed by @tungd here https://stackoverflow.com/a/9459366/7631731. Keeps vim context and handles correctly URLS containing "#".

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

提交回复
热议问题