代码之家  ›  专栏  ›  技术社区  ›  Glennular

在Vim中打开URL的最佳方法

  •  24
  • Glennular  · 技术社区  · 14 年前

    • 右键单击并将链接另存为?
    • 使用默认为Vim的特定文件扩展名?
    3 回复  |  直到 14 年前
        1
  •  39
  •   speshak    9 年前

    根据vim二进制文件的构建方式,您只需给vim一个url:

    vim http://www.google.com/

    Vim生成curl并获取文件,然后打开它。

        2
  •  6
  •   Matthew J Morrison    14 年前

    curl http://www.google.com | vim -
    

    为了使这个命令更容易,你可以随时使用你选择的浏览器的“复制链接地址”选项。

    编辑 考虑到@speshak的答案和我自己的答案,我认为“最简单”的方法是选项3,“命令行命令”。

        3
  •  0
  •   Carson    4 年前

    " gvimrc
    
    for g:chrome_exe in [
        \'C:\...\Google\Chrome\Application\chrome.exe',
        \]
        if !filereadable(g:chrome_exe)
            continue
        endif
        command -nargs=+ URL :exe "silent !start ".g:chrome_exe." <args>"
        break
    endfor
    

    现在键入: :URL https://news.google.com/topstories?hl=en-US&gl=US&ceid=US:en 它会打开的 google news


    或者如果你有一个记录了很多URL的文件,并且你想用热键打开它,那么你可以用这种方式来尝试

    " .gvimrc
    let g:chrome_exe = 'C:/.../Google/Chrome/Application/chrome.exe'
    
    function OpenURL()
        normal "*yy
        " let result = getreg("x")
        " return result
        :execute "silent !start ".g:chrome_exe2." ".getreg("*")
    endfunction
    
    map ,url :call OpenURL()<CR>
    

    ,url

    " test.txt
    https://www.google.com/
    https://news.google.com/topstories?hl=en-US&gl=US&ceid=US:en
    

    指令说明

    统一资源定位地址 是一个名字,由你选择(记住,用户定义的命令必须以 (字母)

    什么是 command

    command -nargs=+ Say :echo "<args>"
    

    :Say Hello World

    Vim呼应“你好世界”。

    纳格斯

    • -nargs=1一个参数
    • -纳格斯=?零个或一个参数
        4
  •  -4
  •   Avinash Kumar    9 年前

    我用过 links

    links http://www.google.com

    如果 链接 没有安装,可以吗 sudo apt-get install links

    希望有帮助。