Skip to content

Vim Installation and Setup

This guide covers how to install Vim on Windows, add it to your system's PATH, and set up the basic configuration. It also addresses common issues like setting the display language and managing multiple Vim installations.

Installing Vim

First, download and install Vim 9.1 to C:\Program Files\Vim, selecting "English" as the installation language.

However, you might find that Vim's interface still displays in your system's native language (e.g., Chinese on a Chinese version of Windows). For instance, when entering Insert mode, the status line might show --插入-- instead of -- INSERT --.

To force Vim's interface language to English, add the following lines to your ~/.vimrc configuration file:

vim
" Set the menu and messages to English
set langmenu=en_US
let $LANG='en_US'
source $VIMRUNTIME/delmenu.vim
source $VIMRUNTIME/menu.vim

Adding Vim to the Environment Path

Adding Vim to your system's environment path allows you to launch it directly from any terminal (like PowerShell or Command Prompt) by simply typing vim <path/to/file>.

If you installed Vim via the official installer, the executable is typically located at: C:\Program Files\Vim\vim91

Alternatively, if you have Git for Windows installed, it comes bundled with a terminal-based version of Vim. You can add its path to your environment variables as well: C:\Program Files\Git\usr\bin

Vim Configuration

You can find key information about your Vim installation using these commands in Vim's command mode:

  • Check Vim version:

    vim
    :version
  • Find important directories:

    vim
    :echo $VIM           " -> C:\Program Files\Vim
    :echo $HOME          " -> C:\Users\YourUsername
    :echo $VIMRUNTIME    " -> C:\Program Files\Vim\vim91

These directories are referred to as the Vim directory, home directory, and Vim runtime directory, respectively.

For consistency across platforms (Windows, macOS, Linux), it's best practice to create your Vim configuration file, .vimrc, in your user home directory ($HOME).

On Windows, the system-wide configuration file is _vimrc located in the Vim installation directory (e.g., C:\Program Files\Vim\_vimrc). If you have trouble modifying it, try running your text editor as an administrator or adjusting the file's security permissions to give your user account "Full control".

Handling Multiple Vim Installations

It's common to have multiple Vim installations on one machine. For example, one from the official Windows installer and another that comes with Git for Windows. While both can be used, they have key differences.

  • Official Vim (from vim.org):

    • Features: This is a full-featured build. It includes the GUI version (GVim), support for system clipboard (+clipboard), and is often compiled with support for scripting languages like Python and Lua, which are required by many advanced plugins.
    • Runtime: Uses a standard Windows runtime environment. Executable is typically at C:\Program Files\Vim\vim91\vim.exe.
  • Vim (bundled with Git for Windows):

    • Features: This is a minimal, terminal-only (TUI) build designed for use within the Git Bash environment. It often lacks features like system clipboard integration (-clipboard), meaning you can't easily copy and paste between Vim and other Windows applications. It may also lack scripting language support.
    • Runtime: Runs in a POSIX compatibility layer (MinGW). Its runtime path (/usr/share/vim/vim91/) is different from the native Windows version.

Key Drawbacks of Git for Windows' Vim:

  • No System Clipboard: The biggest limitation. You have to rely on terminal-specific methods for copy-paste, which can be clumsy.
  • Missing Plugin Support: Many modern plugins that depend on Python, Lua, or other interpreters will not work.
  • No GVim: You lose the benefits of the graphical interface, such as font rendering and mouse support that feels more native to Windows.

Both versions will load the same user configuration from ~/.vimrc, but some settings may behave differently due to the feature discrepancies.

Recommendation

For a daily driver and a full-fledged Vim experience on Windows, use the official Vim distribution from vim.org. It provides all the features, including GVim and crucial plugin support, that you'll want for serious development and writing.

The Vim that comes with Git for Windows is best treated as a convenient utility for quick edits from the Git Bash terminal, such as writing commit messages. By ensuring the official Vim path appears first in your system's PATH environment variable, you can make it the default vim command across all terminals.

最近更新