0.2 — Installing and Launching Vim
0.2 — Installing and Launching Vim#
Before we can start learning Vim, we need to have it installed on our system. In this lesson, we’ll cover installation on major operating systems and how to launch Vim for the first time.
Checking if Vim is Already Installed#
Vim (or at least vi) is pre-installed on most Unix-like systems. Open your terminal and type:
vim --version
If Vim is installed, you’ll see version information and a list of features. If not, you’ll see a “command not found” error.
You can also check for the basic vi editor:
vi --version
Installation by Operating System#
macOS#
macOS comes with a basic version of Vim pre-installed. However, you may want a more feature-rich version:
Using Homebrew (recommended):
brew install vim
For Neovim (modern fork):
brew install neovim
After installation, you may need to restart your terminal or add the Homebrew bin to your PATH.
Linux#
Most Linux distributions include Vim, but you can install or upgrade it:
Debian/Ubuntu:
sudo apt update
sudo apt install vim
Fedora:
sudo dnf install vim
Arch Linux:
sudo pacman -S vim
For Neovim:
# Ubuntu/Debian
sudo apt install neovim
# Fedora
sudo dnf install neovim
# Arch
sudo pacman -S neovim
Windows#
Using Winget:
winget install vim.vim
Using Chocolatey:
choco install vim
Using Scoop:
scoop install vim
Manual Installation: Download the installer from vim.org/download.
For WSL users: If you use Windows Subsystem for Linux, follow the Linux instructions within your WSL distribution.
Vim vs Neovim#
You’ll often hear about Neovim as an alternative to Vim. Here’s a quick comparison:
| Feature | Vim | Neovim |
|---|---|---|
| Compatibility | Original | 99% Vim-compatible |
| Configuration | Vimscript, Lua (9.0+) | Lua preferred |
| Modern Features | Available | Built-in LSP, Treesitter |
| Community | Mature, stable | Active, modern |
For this course, we’ll focus on concepts that work in both. The commands and techniques you learn will transfer seamlessly between Vim and Neovim.
Launching Vim#
Basic Launch#
To launch Vim with an empty buffer:
vim
To open a specific file:
vim filename.txt
To open multiple files:
vim file1.txt file2.txt file3.txt
Launching Neovim#
If you’re using Neovim, replace vim with nvim:
nvim
nvim filename.txt
Command-Line Options#
Vim has many command-line options. Here are the most useful:
| Option | Description |
|---|---|
vim filename | Open a file |
vim +10 filename | Open file and jump to line 10 |
vim +/pattern filename | Open file and search for pattern |
vim -R filename | Open file in read-only mode |
vim -d file1 file2 | Open files in diff mode |
vim -o file1 file2 | Open files in horizontal splits |
vim -O file1 file2 | Open files in vertical splits |
Your First Vim Session#
Let’s launch Vim and understand what we see:
- Open your terminal
- Type
vimand press Enter
You should see something like:
~
~
~ VIM - Vi IMproved
~
~ version 9.0
~ by Bram Moolenaar et al.
~
~ Vim is open source and freely distributable
~
~ type :help iccf<Enter> for information
~ type :q<Enter> to exit
~ type :help<Enter> for on-line help
~ type :help version9<Enter> for version info
~
~
Understanding the Screen#
- Tilde lines (~): Indicate lines beyond the end of the buffer (empty space)
- Status line: At the bottom, shows file info and cursor position
- Command line: The very bottom line where you type Ex commands
Important: You’re Now in Normal Mode#
When Vim launches, you’re in Normal mode. This is crucial to understand:
- Pressing letter keys does NOT type those letters
- Instead, letters trigger commands
- To type text, you must enter Insert mode first
Don’t panic! In the next lesson, we’ll cover the survival basics, including how to safely exit Vim.
Getting Help#
Vim has an extensive built-in help system:
:help " Open help
:help topic " Help on specific topic
:help :w " Help on the :w command
:help i " Help on the i command
:q " Close help window
The help system uses hyperlinks—press Ctrl-] on a highlighted topic to jump to it, and Ctrl-o to jump back.
Practice Exercise#
- Open your terminal
- Check your Vim version:
vim --version - Launch Vim:
vim - Look at the welcome screen
- Type
:qand press Enter to exit
Congratulations! You’ve successfully launched and exited Vim. In the next lesson, we’ll cover the essential survival commands you need to know.
Summary#
| Task | Command |
|---|---|
| Check Vim version | vim --version |
| Launch Vim | vim |
| Open a file | vim filename |
| Open file at line N | vim +N filename |
| Open help | :help |
| Exit Vim | :q |