我是否需要测试 .vim/autoload/plug.vim 在 运行 之前是否存在?

Do I need to test if .vim/autoload/plug.vim exists before running it?

我是否需要测试 .vim/autoload/plug.vim 在 运行 之前是否存在?

我正在研究由 https://vim-bootstrap.com/ 生成的 vimrc,其中一个的第一行是:

let vimplug_exists = expand('~/.vim/autoload/plug.vim')
if !filereadable(vimplug_exists)
  if !executable("curl")
    echoerr "You have to install curl or first install vim-plug yourself!"
    execute "q!"
  endif
  echo "Installing Vim-Plug..."
  echo ""
  silent !\curl -fLo ~/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
  " let g:not_finish_vimplug = "yes"

  autocmd VimEnter * PlugInstall
endif

" Required:
call plug#begin(expand('~/.vim/plugged'))
...

然后是很多Plug '.../...'。这样做的目的是什么?另外,我不明白 autocmd VimEnter * PlugInstall 在做什么。

vimrc 文件正在使用 vim-plug 管理插件。

vim-插件快速概览:

  • 使用Plug {github-user}/{repo}使用指定的插件库
  • Plug语句应该在call plug#begin()call plug#end()
  • 之间
  • plug#begin({dir}) 可以指定目录,{dir},其中 vim-plug 控制的插件将存在
  • :PlugInstall 将对所有定义的插件进行任何必要的获取和安装
  • if executable('curl') 检查以确保您有一个可执行的 curl 程序。这个是用来下载vim-plug

大部分代码是为了确保 vim-plug 存在并尝试自行安装。

意见:避免 Vim 分布

个人感觉 vim-bootstrap 是一个 Vim 分布。我必须警告你,使用一堆插件和自定义的 vimrc 文件进入 Vim 是非常有吸引力的。但是,我建议您避免分发和自定义 vimrc 文件。这些发行版通常让人感觉像是一个不同的编辑器,或者向您推销这些 "must have" 插件的想法。这通常会导致较新的 Vim 用户对香草 Vim 结束和他们的插件开始的地方感到困惑。在自定义 Vim 时,较新的 Vim 用户通常不具备理解和维护其发行版 vimrc 设置所需的先决知识。相反,我建议慢慢学习和构建你自己的 vimrc。基本上"sharpen the saw"


重新发布Learning Vim after vimtutor

把锯子磨快

最好的一般性建议很简单,“Sharpen the saw" from Bram's Seven habits essay. I also suggest Vimcasts blog post: On sharpening the saw

基本上"sharpening the saw"可以概括为:

Don't learn everything all at once, but learn a few things at a time. When you find an inefficiency look for ways to improve it. Repeat

Vimrc

我也推荐你使用nearly blank vimrcvimrc 中的每一行你应该大致理解了。使用 :help 和 google 了解更多。

插件

一般插件建议:

  • 需要时慢慢添加一两个插件。
  • 不要在没有先寻找本机解决方案的情况下安装插件
  • 必须有良好的文档
  • 避免使用具有很多映射的插件
  • 如果感觉不像Vim那么避免
  • 避免映射不适用于 . 命令(可能必须使用 repeat.vim

更多了解Vim

的好地方

TL;DR

阅读 :help 并尝试对您的工作流程进行小的增量更改。