Vim - Installation & Configuration
Vim - Installation and Configuration
Section titled “Vim - Installation and 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.
Installation on Windows
Section titled “Installation on Windows”Vim for Windows typically includes both a command-line version (vim.exe) and a graphical version (gvim.exe).
Installation Methods
Section titled “Installation Methods”- 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
- Chocolatey:
-
- Scoop:
scoop install vim
- Scoop:
- 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).
Configuration File
Section titled “Configuration File”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)”Installation
Section titled “Installation”Use the apt package manager. Open a terminal and execute:
sudo apt updatesudo apt install vimTo ensure Vim is correctly installed, check its location:
which vimThis should print the path to the Vim binary, typically /usr/bin/vim.
Configuration File
Section titled “Configuration File”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 $HOMECreate 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)”Installation
Section titled “Installation”Use dnf (on modern Fedora/RHEL) or yum (on older CentOS/RHEL). Open a terminal and execute:
For DNF-based systems:
sudo dnf install vimFor YUM-based systems:
sudo yum install vimVerify the installation:
which vimConfiguration File
Section titled “Configuration File”Similar to Debian-based systems, the configuration file is $HOME/.vimrc.
Basic Vim Configuration (vimrc)
Section titled “Basic Vim Configuration (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 numbersset number
" Enable syntax highlightingsyntax enable
" Use spaces instead of tabsset expandtab" Number of spaces for a tabset tabstop=4" Number of spaces for auto-indentset shiftwidth=4
" Enable file type detection, plugins, and indentation rulesfiletype plugin indent on
" Highlight search resultsset hlsearch" Incrementally search as you typeset incsearch
" Show a ruler with cursor positionset ruler
" Enable mouse support in all modes (useful for gVim or some terminals)" set mouse=aComments 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.