Open URL under cursor in Vim with browser

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

    As described above by @kev, modified for Linux environments.

    Aside: when this function was executed (Vim 8.1) in my terminal, the Vim screen was obfuscated (mostly "blanked;" i.e., the text was there but not visible). The :redraw! command (see https://stackoverflow.com/a/1117742/1904943) redraws the screen.

    Add to ~/.vimrc:

    nmap g :call Google():redraw!
    fun! Google()
      let keyword = expand("")
      let url = "http://www.google.com/search?q=" . keyword
      let path = "/usr/bin/"
      exec 'silent !"' . path . 'firefox" ' . url
    endfun
    
    

提交回复
热议问题