假设您在网页上有网址或链接,而该网页是文本文件。如何才能让用户在Vim中打开该文件的最简单方法是什么?
答案 0 :(得分:36)
根据你的vim二进制文件的构建方式,你可以给vim提供url:
vim http://www.google.com/
Vim生成卷曲并抓取文件,然后打开它。
答案 1 :(得分:5)
假设你想在vim中打开一个链接,那么:
curl http://www.google.com | vim -
修改的 为了使这个命令更容易,您可以随时使用您选择的浏览器的“复制链接地址”选项。
修改的 鉴于@ speshak的答案和我自己的答案,我会说“最简单”的方法是选项3,“命令行命令”。
答案 2 :(得分:0)
" 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
URL 是一个名称,由您选择。 (请记住,用户定义的命令必须以大写字母开头)
command -nargs=+ Say :echo "<args>"
现在,当您键入:Say Hello World
Vim回响“ Hello World”。
答案 3 :(得分:-2)
自RedHat时代以来,我使用过links
。命令是
links http://www.google.com
如果未安装links
,您可以在Ubuntu 14.04 LTS上进行sudo apt-get install links
安装。
希望它有所帮助。