Vim is not just a text editor β€” it’s a way of thinking. Unlike traditional editors where you point and click, Vim is a modal editor where every key has a purpose, every keystroke is a command, and your hands never leave the home row. Once you internalize the Vim philosophy, you’ll edit text at the speed of thought.

This complete course takes you from absolute beginner (never opened Vim) to a confident Vim user who can navigate, edit, search, replace, and customize with ease. By the end, Vim will feel like an extension of your brain.

πŸ“– What Is Vim & Why Learn It?

Vim (Vi Improved) is a highly configurable text editor built to enable efficient text editing. It’s a descendant of Vi, the original visual editor created by Bill Joy in 1976. Vim was created by Bram Moolenaar in 1991 and has been actively developed ever since.

Why Vim stands out

  • πŸš€ Speed: Once learned, Vim is faster than any GUI editor for most text operations
  • πŸ–₯️ Everywhere: Pre-installed on every Linux/macOS system. Available on Windows via WSL or GVim
  • πŸ”Œ Extensible: Thousands of plugins for every use case β€” from Python autocomplete to Markdown preview
  • 🎯 Modal editing: Separate modes for navigation, insertion, and commands eliminate the need for mouse + modifier keys
  • πŸ“¦ Lightweight: Runs in a terminal, uses minimal resources. Perfect for servers and SSH sessions
  • ♾️ Free & Open Source: Vim is charityware β€” free to use, and you’re encouraged to help children in Uganda

Vim is the default editor on virtually every Linux distribution. If you SSH into a server and type some command triggers an editor, it’s almost certainly Vim or its minimal version vi. Knowing Vim isn’t optional β€” it’s an essential survival skill for any developer or sysadmin.

βš™οΈ Installation & First Launch

Installation by OS

OS Command
Ubuntu/Debian sudo apt install vim
Fedora/RHEL sudo dnf install vim
Arch Linux sudo pacman -S vim
macOS brew install vim
Windows (WSL) sudo apt install vim (inside WSL)

First Launch

Open your terminal and type:

vim

You’ll see a blank screen with ~ characters. This is the Vim welcome screen. Congratulations β€” you’re now in Normal mode.

To exit Vim (the first thing every beginner needs to know):

:q<Enter>

If you have unsaved changes:

:q!<Enter>

Yes, Vim veterans joke about not being able to exit β€” but the truth is, exiting is trivial once you know the command. Let’s fix that permanently.

🎭 Understanding Vim Modes

Vim’s power comes from its modal nature. Unlike Notepad where every key press inserts a character, Vim has multiple modes, each with a different purpose.

Mode Key to Enter Purpose
Normal Esc Navigate, copy, paste, delete, undo β€” the default mode
Insert i Type and edit text like a normal editor
Visual v Select text character-by-character, line-by-line, or block-wise
Command-Line : Run commands like save, quit, search, replace, set options
Replace R Overwrite characters one by one

The key insight: Normal mode is the resting state. You navigate and manipulate text in Normal mode, briefly enter Insert mode to type, then return to Normal. Your hands stay on the home row (asdf/jkl;) the entire time.

🧭 Basic Navigation

In Normal mode, you move the cursor using these keys instead of arrow keys:

Key Movement Mnemonic
h Left Leftmost key (right hand)
j Down J looks like a down arrow
k Up K points up
l Right Rightmost key

Faster Movement

w     # Jump forward one word
b     # Jump backward one word
e     # Jump to end of current word
0     # Jump to beginning of line
$     # Jump to end of line
^     # Jump to first non-whitespace character
gg    # Jump to beginning of file
G     # Jump to end of file
123G  # Jump to line 123
Ctrl+d  # Move down half a page
Ctrl+u  # Move up half a page
Ctrl+f  # Move forward one full page
Ctrl+b  # Move backward one full page

✏️ Editing Basics

Entering Insert Mode

i     # Insert at cursor position
I     # Insert at beginning of line
a     # Append after cursor
A     # Append at end of line
o     # Open new line below
O     # Open new line above
s     # Delete character and enter insert
S     # Delete entire line and enter insert

Basic Operations

x     # Delete character under cursor
dd    # Delete (cut) current line
yy    # Yank (copy) current line
p     # Paste below cursor
P     # Paste above cursor
u     # Undo
Ctrl+r  # Redo
.     # Repeat last change

Combining Operators with Motions

Vim’s true power emerges when you combine operators (actions) with motions (movements):

dw    # Delete word
d$    # Delete to end of line
d0    # Delete to beginning of line
d3w   # Delete next 3 words
dd    # Delete whole line (special case)
yw    # Yank (copy) word
y$    # Yank to end of line
c3w   # Change (delete + insert) 3 words
ci"   # Change inside quotes
ca(   # Change around parentheses

The pattern is: [count] operator motion. This composability is what makes Vim so powerful β€” dozens of operators Γ— dozens of motions = hundreds of operations you can execute in 2-3 keystrokes.

πŸ” Search & Replace

Searching

/pattern   # Search forward for pattern
?pattern   # Search backward for pattern
n          # Repeat search forward
N          # Repeat search backward
*          # Search forward for word under cursor
#          # Search backward for word under cursor

Find Character on Line

fx    # Jump to next 'x' on the line
tx    # Jump to just before next 'x'
Fx    # Jump to previous 'x'
;     # Repeat last f/t/F/T
,     # Reverse repeat

Substitution (Search & Replace)

:s/old/new          # Replace first occurrence on current line
:s/old/new/g        # Replace all on current line
:%s/old/new/g       # Replace all in entire file
:%s/old/new/gc      # Replace all with confirmation
:3,10s/old/new/g    # Replace in lines 3-10 only

Flags explained:

  • g β€” global (all occurrences on the line)
  • c β€” confirm each replacement
  • i β€” case insensitive
  • I β€” case sensitive (override &ignorecase)

πŸ‘οΈ Visual Mode: Selection Power

v       # Character-wise visual mode
V       # Line-wise visual mode
Ctrl+v  # Block-wise visual mode (select columns)

Once you’ve selected text:

d       # Delete selection
y       # Yank (copy) selection
c       # Change selection (delete + insert)
~       # Toggle case
>       # Indent right
<       # Indent left
J       # Join selected lines into one

Block visual mode (Ctrl+v) is incredibly powerful. You can select a rectangular block of text across multiple lines and edit all at once β€” perfect for adding comments to multiple lines, editing columns, or inserting text at the same position across many lines.

πŸ“‚ Working with Files

:e filename      # Open file
:w               # Save (write)
:w filename      # Save as filename
:wq              # Save and quit
:q               # Quit (fails if unsaved)
:q!              # Force quit (discard changes)
😑               # Save and quit (only if modified)
ZZ               # Save and quit (no colon needed)
:wall            # Save all open buffers
:qall            # Quit all
:w !sudo tee %   # Save a read-only file with sudo

πŸ—‚οΈ Buffers, Windows & Tabs

Buffers (Multiple Files in Memory)

:ls               # List all buffers
:b 3              # Go to buffer 3
:bnext / :bn      # Next buffer
:bprev / :bp      # Previous buffer
:bd               # Delete (close) buffer
:bufdo %s/old/new/gc  # Run command on all buffers

Windows (Split Views)

:sp filename      # Horizontal split
:vsp filename     # Vertical split
Ctrl+w w          # Switch between windows
Ctrl+w h/j/k/l    # Navigate to window (left/down/up/right)
Ctrl+w +/-        # Resize height
Ctrl+w </>        # Resize width
Ctrl+w =          # Equalize all windows
:q                # Close current window

Tabs

:tabnew filename  # Open in new tab
:tabnext / :tabn  # Next tab
:tabprev / :tabp  # Previous tab
:tabclose         # Close current tab
:tabmove 2        # Move tab to position 2
gt                # Go to next tab (normal mode)
gT                # Go to previous tab (normal mode)

πŸš€ Advanced Editing Techniques

Text Objects

Text objects let you operate on logical chunks of text. The pattern is: operator + i/a + object where i = inside, a = around.

ciw   # Change inner word
ci"   # Change inside double quotes
ci'   # Change inside single quotes
ci(   # Change inside parentheses
ci{   # Change inside curly braces
ci[   # Change inside square brackets
cit   # Change inside HTML tag
di"   # Delete inside quotes
da"   # Delete around quotes (includes quotes)
yi}   # Yank inside curly braces
ca>   # Change around HTML tag (includes tags)

Registers

Vim has 26 named registers (a-z) for storing text:

"ayy   # Yank current line into register a
"ap    # Paste from register a
"bdd   # Delete line into register b
:reg   # View all registers
"+y    # Yank into system clipboard
"+p    # Paste from system clipboard

Macros

Macros record a sequence of keystrokes and replay them β€” essential for repetitive tasks:

q{a-z}  # Start recording macro into register (e.g., qa)
q       # Stop recording
@{a-z}  # Play back macro (e.g., @a)
@@      # Repeat last macro
10@a    # Run macro a, 10 times

Marks

Set named bookmarks to jump between positions:

m{a-z}  # Set mark (e.g., ma = mark position as 'a')
`{a-z}  # Jump to mark
'{a-z}  # Jump to line of mark
:marks  # List all marks
``      # Jump back to previous position

⚑ Vimrc Configuration

The ~/.vimrc file controls Vim’s behavior. Here’s a starter config that turns Vim into a modern editor:

" === Basic Settings ===
set nocompatible          " Use Vim settings, not Vi
syntax on                 " Enable syntax highlighting
set number                " Show line numbers
set relativenumber        " Show relative line numbers
set cursorline            " Highlight current line
set tabstop=4             " Tab width = 4 spaces
set shiftwidth=4          " Indent width = 4
set expandtab             " Use spaces instead of tabs
set smartindent           " Auto-indent
set wrap                  " Line wrap
set linebreak             " Break at words (not chars)

" === Search ===
set hlsearch              " Highlight search results
set incsearch             " Show matches as you type
set ignorecase            " Case insensitive search
set smartcase             " Case-sensitive if uppercase in query

" === Interface ===
set showcmd               " Show command in bottom bar
set wildmenu              " Auto-complete menu for commands
set lazyredraw            " Faster scrolling
set showmatch             " Highlight matching brackets
set visualbell            " Flash instead of beep

" === Files & Backup ===
set nobackup              " No backup files
set nowb                  " No write-backup
set noswapfile            " No swap files
set encoding=utf-8

" === Key Mappings ===
" Leader key (comma instead of backslash)
let mapleader = ","
" Quickly edit vimrc
nnoremap <leader>ev :vsplit $MYVIMRC<CR>
" Source vimrc
nnoremap <leader>sv :source $MYVIMRC<CR>
" Clear search highlight
nnoremap <leader>h :nohlsearch<CR>

" === Plugins (via vim-plug) ===
" Install vim-plug: curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
"   https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim

call plug#begin('~/.vim/plugged')
Plug 'preservim/nerdtree'          " File explorer
Plug 'vim-airline/vim-airline'     " Status bar
Plug 'tpope/vim-fugitive'          " Git integration
Plug 'neoclide/coc.nvim', {'branch': 'release'}  " Autocomplete
Plug 'preservim/nerdcommenter'     " Comment toggling
Plug 'sheerun/vim-polyglot'        " Language packs
Plug 'rafi/awesome-vim-colorschemes' " Color themes
call plug#end()

colorscheme gruvbox               " Set color theme

πŸŽ“ Vimtutor β€” Built-in Interactive Course

Vim ships with a built-in tutor called vimtutor. It’s a 30-minute interactive lesson that teaches you the basics. Every Vim beginner should run it:

vimtutor

It opens a file in Vim with instructions. You edit the file as you follow along. Run it multiple times until the commands become muscle memory.

πŸ”Œ Essential Plugins for Daily Use

Plugin Purpose
NERDTree File system explorer in sidebar
vim-airline Beautiful status bar with git branch, file type, position
vim-fugitive Git integration (blame, diff, status)
coc.nvim Language Server Protocol (LSP) client for autocomplete
fzf.vim Fuzzy file search (requires fzf)
vim-commentary Comment/uncomment lines with gc
auto-pairs Auto-close brackets, quotes, parentheses

πŸ“ Quick Reference Cheatsheet

Action Command
Save :w
Save & Quit :wq or ZZ
Quit (no save) :q!
Undo u
Redo Ctrl+r
Copy line yy
Cut line dd
Paste p (after), P (before)
Find & Replace all :%s/old/new/g
Go to line N :N or N G
Search /pattern
Repeat last change .
Set line numbers :set number
Syntax on/off :syntax on
Spell check :set spell
Open file :e filename
Open NERDTree :NERDTreeToggle

πŸ₯Š Vim vs. Other Editors

Feature Vim Nano VS Code Sublime
Learning Curve Steep πŸ§— Flat βœ… Moderate Easy
Editing Speed (expert) Fastest πŸ† Slow Fast Fast
Server-Ready βœ… Yes βœ… Yes ❌ No ❌ No
Plugin Ecosystem Huge πŸ”Œ None Massive Large
Memory Usage ~5MB ~3MB ~400MB ~50MB
Modal Editing βœ… Native ❌ No Via extension Via plugin
Pre-installed on Linux βœ… Yes (vi) βœ… Yes ❌ No ❌ No

🎯 Practice Plan β€” 7 Days to Vim Proficiency

Day Focus Exercise
1 hjkl + vimtutor Run vimtutor chapters 1-2
2 Insert modes + editing vimtutor chapters 3-4
3 Search + replace Edit a real file with /, :%s
4 Visual mode + text objects Use ci", vi{ on code
5 Buffers + windows :sp, :vsp, Ctrl+w
6 Macros + marks Record qa, repeat @a
7 vimrc + plugins Set up your .vimrc

⚠️ Common Mistakes Beginners Make

  1. Staying in Insert mode β€” Return to Normal mode (Esc) between edits. Normal mode is home.
  2. Using arrow keys β€” They work, but they defeat the purpose. Force yourself to use hjkl.
  3. Not using relative line numbers β€” set relativenumber makes 5j or d3k intuitive.
  4. Typing undo repeatedly β€” u undoes one change. A change = insert until you press Esc. Fix large mistakes with U (undo entire line).
  5. Forgetting . β€” The dot command repeats the last change. It’s the single most powerful optimization.
  6. Too many plugins at start β€” Learn the basics first. Add plugins only when you feel pain.

πŸ”§ Troubleshooting Common Issues

Issue Solution
Can’t exit Vim Esc β†’ :q! β†’ Enter
“E212: Can’t open file for writing” :w !sudo tee % (save with sudo)
Vim seems frozen Press Esc several times + Ctrl+q
Accidentally pasted wrong text u to undo
Search highlighting stuck :nohlsearch or :set nohlsearch
Can’t find a file :find filename (searches path)

🏁 Next Steps

You now have a solid foundation in Vim. Here’s where to go from here:

  1. Make Vim your daily driver β€” Edit every config file, code snippet, and note in Vim for at least a week
  2. Install a Vim plugin in your IDE β€” VS Code has an excellent Vim emulator extension that brings modal editing to your IDE
  3. Learn Neovim β€” A modern Vim fork with Lua scripting, better plugin architecture, and speed improvements. Run apt install neovim
  4. Explore :help β€” Vim’s built-in help is comprehensive. Type :help topic for any command
  5. Join the community β€” Reddit r/vim, Vi Stack Exchange, and Vim Tips are great resources

Remember: Vim proficiency comes with deliberate practice. The first week is uncomfortable, but within a month you’ll wonder how you ever lived without it.


More Free Courses on TricksPage

Leave a Reply

Your email address will not be published. Required fields are marked *