以下是逐步排查和解决方案:
1. 确认 GitHub 当前可用 IP
由于 GitHub 的 IP 可能会变动,建议重新获取最新 IP:
# 查询最新 GitHub 域名对应 IP(任选一个工具)
nslookup github.com 8.8.8.8 # 使用 Google DNS
dig github.com @1.1.1.1 # 使用 Cloudflare DNS
将获取的最新 IP 更新到 hosts 文件(通常位于 C:\Windows\System32\drivers\etc\hosts 或 /etc/hosts):
# 示例格式(请替换为实际获取的 IP)
140.82.113.3 github.com
185.199.108.133 raw.githubusercontent.com
2. 强制刷新 DNS 缓存
更新 hosts 后需刷新 DNS:
# Windows
ipconfig /flushdns
# Linux
sudo systemctl restart nscd
# macOS
sudo killall -HUP mDNSResponder
3. 改用 SSH 协议安装插件
修改插件地址为 SSH 格式(需提前配置 SSH Key):
" 在 vimrc 中将 https 地址改为 git@github.com:user/repo.git 格式
Plug 'git@github.com:user/repo.git'
4. 使用镜像加速
如果直连困难,可通过镜像站加速:
" 将 github.com 替换为镜像地址
Plug 'https://hub.fastgit.org/user/repo.git'
或临时设置 git 全局镜像:
git config --global url."https://hub.fastgit.org/".insteadOf https://github.com/
5. 检查代理配置
如果你使用代理,确保 git 和 curl 能识别代理:
# 设置代理(示例为 Clash 默认端口)
git config --global http.proxy http://127.0.0.1:7890
git config --global https.proxy https://127.0.0.1:7890
6. 临时关闭防火墙/安全软件
某些防火墙软件会拦截 Git 请求,尝试暂时关闭它们。
7. 验证网络连通性
手动测试关键域名是否可达:
curl -v https://github.com
curl -v https://raw.githubusercontent.com
如果返回 Connection reset,可能是网络间歇性阻断。
8. 还原 plug.vim 修改
如果之前修改过 plug.vim 的下载源,尝试恢复原始配置:
" 原始下载命令
let g:plug_url_format = 'https://git::@github.com/%s.git'
9. 终极方案:手动安装
如果自动化安装失败,可手动操作:
# 进入插件目录
cd ~/.vim/plugged/
# 手动克隆仓库
git clone https://github.com/user/repo.git
然后在 Vim 中运行 :PlugInstall 跳过已安装插件。