This page looks best with JavaScript enabled

Installing and Configuring Vim on Windows

 ·  ☕ 3 min read

1. Introduction to Vim

Vim is an editor that evolved from vi; its first version was released by Bram Moolenaar in 1991. The original name was Vi IMitation, and as features accumulated it was officially renamed Vi IMproved.

The image above shows the learning curves of common editors. For most users, Vim has a fairly steep learning curve. That is, at the beginning you feel it is hard going, and you may even give up. But once you have mastered a few basic operations, it can greatly improve your editing efficiency. That is also the main reason I learned Vim.

Here is the Vim download page. Since the production PCs come with Windows OS preinstalled, I chose gvim.

2. The vimrc Configuration File

Vim’s strength is that it can be configured to meet all kinds of development needs.

On Windows, Vim’s configuration file is named _vimrc and lives in Vim’s installation directory. On Linux systems, the configuration file is named .vimrc. This is because filenames starting with a dot are not legal on Windows.

3. Installing the Plugin Manager Vundle

There are many Vim plugin managers, for example Pathogen, Vundle, NeoBundle, and VAM. But Vundle has the most users managing plugins with it.

Managing plugins with Vundle is like maintaining a requirements.txt or a package.json. The difference is that here you are maintaining the vimrc file.

3.1 Installing git and curl

Vundle depends on the git and curl commands. Here they are installed through chocolatey. chocolatey is a package manager tool for Windows, similar to apt-get or yum.

Run the following command with administrator privileges to install chocolatey:

1
 @"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"

Then run the following commands to install git and curl:

1
2
choco install -y git
choco install -y curl

3.2 Installing Vundle

In Vim’s installation directory, find vimfiles and create a bundle folder inside it.

In the Vim/vimfiles/bundle directory, run:

1
git clone https://github.com/VundleVim/Vundle.vim.git

4. Installing Plugins with Vundle

4.1 Installing Plugins

With Vundle, there are two ways to install a plugin through the vimrc configuration file:

  • Between vundle#begin() and vundle#end(), add the line Plugin '插件名'
  • Add a single line Bundle '插件名' directly

It is worth mentioning how to obtain a plugin name.

First go to github and find the plugin you need, say a plugin for formatting frontend code. The plugin’s github address is: https://github.com/maksimr/vim-jsbeautify . Here maksimr/vim-jsbeautify is the plugin name Vundle needs. Of course, Vundle does not only support network installation from github; for other sources you need to give the full git address.

When installing, add the following to the vimrc file:

1
2
3
4
5
6
7
8
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
" javascript,html,css,json格式化工具
Plugin 'maksimr/vim-jsbeautify'
call vundle#end()

" 文档树
Bundle 'scrooloose/nerdtree'

On Windows, find the Gvim icon and click it to open it. Then run :PluginInstall, and the plugin is installed. As shown below:

Besides installing from Vim’s normal mode, you can also run the command directly

1
 vim -E -u _vimrc +qall

4.2 Common Vundle Commands

In normal mode, run the commands:

1
2
3
4
:PluginInstall // 安装插件
:BundleInstall // 安装插件
:BundleInstall! // 更新插件
:BundleClean // 卸载插件

5. Using the Vim in git bash

However, under Windows the Gvim window is the same size as a Dos window. So it is recommended to install Git for Windows and use Vim in Git Bash, download page.

The large-screen effect:

  • Install Vundle
1
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
  • Edit the vimrc configuration file
1
vim ~/.vimrc

Here the configuration file name and path are the same as on Linux.

Paste Vundle’s official example configuration

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
set nocompatible              " 去除VI一致性,必须
filetype off                  " 必须

" 设置包括vundle和初始化相关的runtime path
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" 另一种选择, 指定一个vundle安装插件的路径
"call vundle#begin('~/some/path/here')

" 让vundle管理插件版本,必须
Plugin 'VundleVim/Vundle.vim'

" 以下范例用来支持不同格式的插件安装.
" 请将安装插件的命令放在vundle#begin和vundle#end之间.
" Github上的插件
" 格式为 Plugin '用户名/插件仓库名'
Plugin 'tpope/vim-fugitive'
" 来自 http://vim-scripts.org/vim/scripts.html 的插件
" Plugin '插件名称' 实际上是 Plugin 'vim-scripts/插件仓库名' 只是此处的用户名可以省略
Plugin 'L9'
" 由Git支持但不再github上的插件仓库 Plugin 'git clone 后面的地址'
Plugin 'git://git.wincent.com/command-t.git'
" 本地的Git仓库(例如自己的插件) Plugin 'file:///+本地插件仓库绝对路径'
Plugin 'file:///home/gmarik/path/to/plugin'
" 插件在仓库的子目录中.
" 正确指定路径用以设置runtimepath. 以下范例插件在sparkup/vim目录下
Plugin 'rstacruz/sparkup', {'rtp': 'vim/'}
" 安装L9,如果已经安装过这个插件,可利用以下格式避免命名冲突
Plugin 'ascenator/L9', {'name': 'newL9'}

" 你的所有插件需要在下面这行之前
call vundle#end()            " 必须
filetype plugin indent on    " 必须 加载vim自带和插件相应的语法和文件类型相关脚本
" 忽视插件改变缩进,可以使用以下替代:
"filetype plugin on
"
" 简要帮助文档
" :PluginList       - 列出所有已配置的插件
" :PluginInstall    - 安装插件,追加 `!` 用以更新或使用 :PluginUpdate
" :PluginSearch foo - 搜索 foo ; 追加 `!` 清除本地缓存
" :PluginClean      - 清除未使用插件,需要确认; 追加 `!` 自动批准移除未使用插件
"
" 查阅 :h vundle 获取更多细节和wiki以及FAQ
" 将你自己对非插件片段放在这行之后

6. References


微信公众号
WRITTEN BY
微信公众号