Installation and Setup
Summary: in this tutorial, you will learn install vim on windows, macos, and linux, and configure a sensible starter vimrc for a comfortable editing experience.
Installation and Setup
Before we start exploring Vim's features, let's make sure it's properly installed on your computer and set up with sensible default settings. This tutorial covers every major platform and walks you through creating a configuration file so Vim feels comfortable from day one.
What you'll learn in this tutorial:
- How to check if Vim is already installed on your computer
- How to install Vim on Linux, macOS, or Windows
- What a "vimrc" configuration file is and why you need one
- How to set up sensible defaults that make Vim much easier to use
- How to create custom keyboard shortcuts
Checking If Vim Is Already Installed
Vim might already be on your computer! Let's check. Open your terminal and type:
vim --versionIf you see a message starting with VIM - Vi IMproved followed by a version number, Vim is already installed and you can skip ahead to the Configuring Vim section below.
If you see an error like "command not found" or "'vim' is not recognized," follow the installation steps below for your operating system.
Installing on Linux
Linux is the operating system used on most servers and many developer computers. If you're running Linux, here's how to install Vim:
Ubuntu / Debian
These are two of the most popular Linux distributions (versions of Linux). Open your terminal and run these two commands:
sudo apt update
sudo apt install vimWhat do these commands mean?
sudostands for "Super User DO." It gives you administrator permissions to install software. You'll be asked to type your password (the characters won't show as you type — that's normal).aptis a package manager — a tool that downloads and installs software for you. Think of it like an app store, but you type commands instead of clicking.apt updaterefreshes the list of available software so you get the latest version.apt install vimdownloads and installs Vim.
For the full-featured build (includes clipboard support so you can copy/paste between Vim and other programs):
sudo apt install vim-gtk3Fedora / RHEL / CentOS
sudo dnf install vim-enhanceddnf is the package manager for Fedora-based Linux systems — it works just like apt on Ubuntu but with a different name.
Arch Linux
sudo pacman -S vimpacman is Arch Linux's package manager. The -S flag means "sync" (install).
Installing on macOS
macOS comes with a basic version of vi (the older, limited editor), but we want the full Vim with all its features.
Using Homebrew (Recommended)
Homebrew is the most popular package manager for macOS — it lets you install software using terminal commands. If you don't have Homebrew yet, install it first by visiting brew.sh and following the one-line installation command on that page.
Once Homebrew is installed, run:
brew install vimThis installs the latest version of Vim with all features enabled. Verify it worked:
vim --version | head -1You should see something like VIM - Vi IMproved 9.x.
What does | head -1 mean? The | (pipe) symbol takes the output of one command and feeds it into another. head -1 shows only the first line. So vim --version | head -1 shows just the first line of Vim's version info instead of a long list.
Using MacVim (GUI Version)
If you prefer a version with a traditional Mac window (with menus, scroll bars, etc.):
brew install --cask macvimMacVim gives you the mvim command and a native macOS application window. Most of this tutorial series uses terminal Vim, but MacVim works the same way.
Installing on Windows
Using winget (Built-in, Simplest Method)
Windows 10 and 11 include a built-in package manager called winget. Open PowerShell or Command Prompt and run:
winget install vim.vimUsing Chocolatey
Chocolatey is a popular third-party package manager for Windows. If you have it installed:
choco install vimUsing Scoop
Scoop is another Windows package manager favored by developers:
scoop install vimManual Download
You can also download the installer directly from vim.org and run the setup wizard, just like installing any other Windows program.
Windows users: The Vim installer will ask if you want to add Vim to your PATH (which lets you run vim from any terminal window). Say yes! You can run Vim inside Windows Terminal, PowerShell, Command Prompt, or Git Bash.
Neovim — A Modern Alternative
You may also hear about Neovim (neovim.io), which is a modernized version of Vim. Think of it like Vim 2.0 — it has the same commands and keybindings, but with better plugin support and some modern improvements under the hood.
Everything in this tutorial series works with both Vim and Neovim. If you want to try Neovim:
# Install Neovim on macOS:
brew install neovim
# Install Neovim on Ubuntu/Debian:
sudo apt install neovim
# Install Neovim on Windows:
winget install Neovim.NeovimRun Neovim with nvim instead of vim. For this tutorial series, we'll use vim in all examples, but you can substitute nvim if you prefer.
Configuring Vim — The vimrc File
What Is a vimrc?
A vimrc (pronounced "vim-are-see") is a plain text file that contains your personal Vim settings. Every time Vim starts up, it reads this file and applies your preferences — things like "show line numbers," "use spaces instead of tabs," and "enable syntax highlighting" (which colors your code to make it easier to read).
Think of the vimrc as Vim's settings file, similar to the Settings or Preferences panel in other apps.
The vimrc file lives at different locations depending on your operating system:
| Operating System | vimrc Location |
|---|---|
| Linux / macOS | ~/.vimrc (the ~ means your home folder) |
| Windows | ~/_vimrc or $HOME/_vimrc |
| Neovim | ~/.config/nvim/init.vim |
Creating Your First vimrc
Let's create a vimrc with sensible defaults that will make Vim much more pleasant to use. Open your terminal and type:
vim ~/.vimrcThis opens Vim to edit your vimrc file. If the file doesn't exist yet, Vim will create it when you save. Now press i to enter Insert mode, and type (or paste) the following configuration:
" ======================================
" General Settings
" ======================================
" Lines starting with " are comments — Vim ignores them.
" They're just notes to help you understand each setting.
set nocompatible " Use Vim's features, not old Vi compatibility mode
filetype plugin indent on " Detect file types and apply appropriate settings
syntax on " Enable syntax highlighting (code gets colored!)
" ======================================
" Display — How Vim Looks
" ======================================
set number " Show line numbers on the left side
set relativenumber " Also show relative line numbers (helps with navigation)
set cursorline " Highlight the line your cursor is on
set showmatch " Briefly highlight the matching bracket when you type one
set showcmd " Show partial commands in the bottom-right corner
set ruler " Show your cursor position (line and column number)
set laststatus=2 " Always show the status bar at the bottom
set signcolumn=yes " Always show the sign column (prevents the screen from jumping)
" ======================================
" Search — How Finding Text Works
" ======================================
set incsearch " Start showing results as you type your search
set hlsearch " Highlight ALL matches, not just the one you're on
set ignorecase " Searches are case-insensitive by default
set smartcase " BUT if you type an uppercase letter, search becomes case-sensitive
" ======================================
" Indentation — How Tabs and Spacing Work
" ======================================
set expandtab " When you press Tab, insert spaces (not a tab character)
set shiftwidth=4 " Each level of indentation is 4 spaces
set tabstop=4 " A tab character displays as 4 spaces wide
set softtabstop=4 " Pressing the Tab key inserts 4 spaces
set autoindent " New lines automatically match the indentation of the previous line
set smartindent " Vim tries to guess the correct indentation level
" ======================================
" Editing — How Editing Feels
" ======================================
set backspace=indent,eol,start " Backspace works normally (fixes a common annoyance)
set clipboard=unnamedplus " Copy/paste works with your system clipboard
set mouse=a " Enable mouse support (click to position cursor)
set scrolloff=8 " Always keep 8 lines visible above and below your cursor
set sidescrolloff=8 " Always keep 8 columns visible left and right of your cursor
" ======================================
" Files — How Vim Handles Files
" ======================================
set encoding=utf-8 " Use modern text encoding (supports all languages and emojis)
set nobackup " Don't create annoying backup files ending in ~
set nowritebackup " Don't create temporary write-backup files
set noswapfile " Don't create .swp swap files (they clutter your folders)
set autoread " If a file changes outside Vim, automatically reload it
set hidden " Allow switching between files without forcing you to save first
" ======================================
" Completion — Autocomplete Behavior
" ======================================
set wildmenu " Show a visual menu when pressing Tab in command mode
set wildmode=longest:full,full " Tab completion: first match longest common string, then cycle
set completeopt=menuone,noselect " Autocomplete menu shows even for one match
" ======================================
" Performance
" ======================================
set updatetime=300 " Faster response time (milliseconds) for certain features
set timeoutlen=500 " How long Vim waits for you to complete a key sequence
set ttyfast " Assume a fast terminal connection (smoother scrolling)
set lazyredraw " Don't redraw the screen while running macros (faster)After typing or pasting all of that, press Escape to return to Normal mode, then type :wq and press Enter to save and quit.
Don't memorize all of this! You don't need to understand every setting right now. This is a "set it and forget it" configuration that makes Vim comfortable to use. You can always come back later and tweak individual settings as you learn what they do.
Understanding vimrc Syntax
The vimrc file uses a very simple format:
" This is a comment — Vim ignores everything after the " symbol
set option " Turn ON a feature (like set number turns on line numbers)
set nooption " Turn OFF a feature (like set nonumber turns off line numbers)
set option=value " Set a feature to a specific value (like set shiftwidth=4)You can also check what any setting is currently set to by typing these commands inside Vim:
:set number? " Shows whether line numbers are currently on or off
:set shiftwidth? " Shows the current indentation widthReloading your vimrc: You don't need to close and reopen Vim after editing your vimrc. From inside Vim, run :source ~/.vimrc to apply the changes immediately.
Essential Key Mappings (Custom Shortcuts)
One of Vim's best features is the ability to create your own keyboard shortcuts, called mappings. Add these to your vimrc for quality-of-life improvements:
" ======================================
" Custom Keyboard Shortcuts (Mappings)
" ======================================
" Set the 'leader' key to the Space bar.
" The leader key is a prefix for custom shortcuts.
" For example, <leader>w means: press Space, then press w.
let mapleader = " "
" Press Space then w to SAVE your file quickly
nnoremap <leader>w :w<CR>
" Press Space then q to QUIT quickly
nnoremap <leader>q :q<CR>
" Press Space then h to clear search highlighting
nnoremap <leader>h :nohlsearch<CR>
" Use Ctrl+h/j/k/l to move between split windows
" (This replaces the harder-to-type Ctrl-w then h/j/k/l)
nnoremap <C-h> <C-w>h
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-l> <C-w>l
" In Visual mode, move selected lines up with K and down with J
vnoremap J :m '>+1<CR>gv=gv
vnoremap K :m '<-2<CR>gv=gv
" When searching, keep the match in the center of the screen
nnoremap n nzzzv
nnoremap N Nzzzv
" When indenting in Visual mode, stay in Visual mode
" (Normally Vim kicks you back to Normal mode after indenting)
vnoremap < <gv
vnoremap > >gvWhat Do These Mapping Commands Mean?
Don't worry about memorizing the mapping syntax. Here's a quick reference:
| Command | What It Means |
|---|---|
nnoremap | Create a shortcut that works in Normal mode |
vnoremap | Create a shortcut that works in Visual mode |
inoremap | Create a shortcut that works in Insert mode |
<CR> | Represents the Enter key |
<C-h> | Represents Ctrl+h |
<leader> | Represents your leader key (we set it to the Space bar) |
Why noremap instead of map? Always use noremap variants (like nnoremap instead of nmap). The noremap versions are "non-recursive," meaning they won't accidentally trigger other shortcuts and cause confusing chain reactions.
Color Schemes (Making Vim Look Nice)
Vim comes with several built-in color schemes that change how your code and text look. You can try them from inside Vim:
:colorscheme desert
:colorscheme slate
:colorscheme elflordEach command instantly changes the colors. If you find one you like, add it to your vimrc so it loads every time:
colorscheme desertPopular third-party color schemes (that you can install later once you learn about plugins) include gruvbox, onedark, catppuccin, and dracula.
Verifying Your Setup
Let's make sure everything is working correctly. Open Vim:
vimYou should see:
- Line numbers on the left side of the screen
- A highlighted cursor line (the line your cursor is on should look different)
- A status bar at the very bottom of the screen showing information
You can also verify specific settings from inside Vim:
:set number? " Should show 'number' (meaning line numbers are ON)
:set expandtab? " Should show 'expandtab' (meaning Tab inserts spaces)
:set shiftwidth? " Should show 'shiftwidth=4' (meaning 4-space indentation)Type :q to quit when you're done checking.
Built-in Help System
Vim has one of the best built-in help systems of any software. Whenever you're confused about a command, setting, or feature, try:
:help " Open the main help page
:help :w " Get help specifically for the :w (save) command
:help options " See a list of ALL available settings
:help usr_01 " Read the user manual, starting from chapter 1To navigate the help, use j and k to scroll up and down. To close the help window, type :q.
Summary
Here's what you've accomplished in this tutorial:
- Checked if Vim is installed on your computer (and installed it if not)
- Created a vimrc configuration file with sensible default settings
- Set up display settings like line numbers, syntax highlighting, and a status bar
- Configured search, indentation, and editing preferences for a comfortable experience
- Added custom keyboard shortcuts to save time on common operations
- Learned about color schemes to make Vim look nice
- Discovered the built-in help system with
:helpfor when you need guidance
In the next tutorial, you'll learn about Vim's modes in depth and how to navigate through files quickly.
Practice: Set Up Your Vim Environment
Complete these steps to confirm everything is working:
- Run
vim --versionin your terminal and check that you see a version number - Create (or verify) your
~/.vimrcfile with the settings from this tutorial - Open Vim and confirm you see line numbers, a highlighted cursor line, and a status bar
- Try changing the color scheme with
:colorscheme desert - Try the help system with
:helpand then close the help window with:q
Show Solution
# Step 1: Check your Vim version
vim --version
# Look for "VIM - Vi IMproved" followed by a version number
# For example: VIM - Vi IMproved 9.0
# Step 2: Open your vimrc to verify settings are there
vim ~/.vimrc
# You should see all the settings from this tutorial
# Type :q to exit
# Step 3: Open Vim and check the display
vim
# You should see:
# - Numbers on the left side (line numbers)
# - The current line highlighted (cursorline)
# - A status bar at the very bottom
# Type :q to exit
# Step 4: Test a color scheme
vim
# Type :colorscheme desert and press Enter
# The colors should change immediately!
# Type :q to exit
# Step 5: Try the help system
vim
# Type :help and press Enter
# A help window opens with documentation
# Scroll around with j (down) and k (up)
# Type :q to close the help window
# Type :q again to exit VimWritten by the ShellRAG Team
The ShellRAG editorial team writes practical, beginner-friendly Vim tutorials with tested code examples and real-world use cases. Every article is technically reviewed for accuracy and updated regularly.
Learn more about us →