Skip to content

Vim - Installation & Configuration

Vim is a lightweight and widely available text editor. This chapter covers installation on common platforms and initial configuration to get you started.

  • Installation on Windows.
  • Installation on Debian-based Linux (e.g., Ubuntu).
  • Installation on RPM-based Linux (e.g., Fedora, CentOS).
  • Basic Vim configuration.

Vim for Windows typically includes both a command-line version (vim.exe) and a graphical version (gvim.exe).

  • Official Installer: Visit the official Vim website (vim.org/download.php#pc). Download the self-installing executable (e.g., gvim##.exe, where ## is the version number). Run the installer and follow the on-screen instructions.
  • Package Managers: If you use a Windows package manager:
    • Chocolatey: choco install vim
    • Scoop: scoop install vim
  • Windows Subsystem for Linux (WSL): If you have WSL enabled, you can install the Linux version of Vim within your WSL distribution using its package manager (see Linux instructions below).

On Windows, Vim looks for its main configuration file, typically named _vimrc, in your user’s home directory. To find your home directory, you can open Command Prompt and type:

echo %USERPROFILE%

Create a file named _vimrc (ensure it has no extension like .txt) in that directory. For example, C:\Users\YourName\_vimrc.

Another common location, especially for more complex configurations or plugins, is $HOME/vimfiles/vimrc.

Installation on Debian-based Linux (e.g., Ubuntu, Mint)

Section titled “Installation on Debian-based Linux (e.g., Ubuntu, Mint)”

Use the apt package manager. Open a terminal and execute:

sudo apt update
sudo apt install vim

To ensure Vim is correctly installed, check its location:

which vim

This should print the path to the Vim binary, typically /usr/bin/vim.

On Linux and macOS, Vim’s user-specific configuration file is named .vimrc (note the leading dot) and is located in your home directory ($HOME).

To find your home directory:

echo $HOME

Create or edit the file $HOME/.vimrc.

Installation on RPM-based Linux (e.g., Fedora, CentOS, RHEL)

Section titled “Installation on RPM-based Linux (e.g., Fedora, CentOS, RHEL)”

Use dnf (on modern Fedora/RHEL) or yum (on older CentOS/RHEL). Open a terminal and execute:

For DNF-based systems:

sudo dnf install vim

For YUM-based systems:

sudo yum install vim

Verify the installation:

which vim

Similar to Debian-based systems, the configuration file is $HOME/.vimrc.

Your vimrc file (_vimrc on Windows, .vimrc on Linux/macOS) allows you to customize Vim’s behavior. Open this file in a text editor (even Vim itself!) and add settings. Here are some common and useful initial settings:

" Show line numbers
set number
" Enable syntax highlighting
syntax enable
" Use spaces instead of tabs
set expandtab
" Number of spaces for a tab
set tabstop=4
" Number of spaces for auto-indent
set shiftwidth=4
" Enable file type detection, plugins, and indentation rules
filetype plugin indent on
" Highlight search results
set hlsearch
" Incrementally search as you type
set incsearch
" Show a ruler with cursor position
set ruler
" Enable mouse support in all modes (useful for gVim or some terminals)
" set mouse=a

Comments in a vimrc file start with a double quote ("). Save the file, and the next time you start Vim, these settings will apply. You can also reload your vimrc in a running Vim session by sourcing it: :source $MYVIMRC (or :so % if you are editing the vimrc itself).

Note on Neovim: If you are using Neovim, a popular Vim fork, its configuration file is typically located at $HOME/.config/nvim/init.vim (or init.lua). While many Vim settings work in Neovim, it has its own specific features and configuration practices.

Practical Application: A well-configured Vim environment enhances readability and efficiency. Basic settings like line numbers, syntax highlighting, and consistent indentation are fundamental for any coding or text editing task.