使用浏览器在 Vim 中打开光标下的 URL [英] Open URL under cursor in Vim with browser

查看:37
本文介绍了使用浏览器在 Vim 中打开光标下的 URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是第一次使用 Twitvim.看到里面所有的网址让我很纳闷,有没有什么办法可以在你喜欢的浏览器或指定的浏览器中打开光标下的网址?

解决方案

更新:来自 tpope 今天的推文

gx.您可以自定义浏览器.在 Gnome 和 Mac OS X 上,它已经使用 gnome-open/open.通常,您可以将 g:netrw_browsex_viewer 设置为您想要的任何内容.

<小时>

原答案:

不记得我是从哪里得到这个功能的.url 中有一个带有哈希 (#) 的错误,但该函数运行良好,我不会费心修复它.

函数!句柄URL()让 s:uri = matchstr(getline("."), '[a-z]*:\/\/[^ >,;]*')回声:uri如果 s:uri != ""无声执行!打开'".s:uri.'"别的echo "在行中找不到 URI."万一端功能映射<leader>u :call HandleURL()<cr>

注意:如果您使用的不是 Mac,请在 Linux 上使用 gnome-open/xdg-open,或者在 Windows 上使用网络浏览器的路径"

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?

解决方案

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 <leader>u :call HandleURL()<cr>

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

这篇关于使用浏览器在 Vim 中打开光标下的 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆