// The editor that runs the internet.
MOUSE USERS ARE SLOW.
Every second spent reaching for the mouse is a second wasted. Vim's modal editing lets you keep your hands on the keyboard and edit at the speed of thought.
WHY VIM
Vim is everywhere. It's on every Linux system, every server, every container. Learning Vim once means you have a powerful editor everywhere you go.
HJKL YOUR WAY TO SPEED.
12 lessons. Complete Vim mastery.
What is Vim, modes, and why modal editing
BeginnerMoving around with h,j,k,l and beyond
BeginnerEntering and exiting insert mode
Beginnerd, c, x and the vim grammar
Intermediatey, p and the Vim register system
Intermediate/, s, :%s and regular expressions
Intermediatev, V, Ctrl+v for block selection
IntermediateRecording and replaying commands with q
AdvancedEditing multiple files with splits
AdvancedManaging multiple files in Vim
Advanced.vimrc and essential settings
AdvancedExtending Vim with plugins
AdvancedVim is the editor that runs the world's infrastructure. Every Linux server, every container, every terminal has Vim. Master it once and you have a superpower everywhere.
The investment: 2 weeks of practice. The payoff: 10x editing speed for the rest of your career.
What you'll master: Modal editing, navigation, text objects, macros, splits, and automation. By the end, you'll edit faster than you can think.
Quit the mouse. Save the world.
Vim (Vi IMproved) is a modal text editor. Unlike most editors where you just type, Vim has different modes for different tasks. This seems strange at first, but it's incredibly powerful.
i # Enter Insert mode (before cursor)
a # Enter Insert mode (after cursor)
Esc # Return to Normal mode
v # Enter Visual mode
V # Enter Visual Line mode
Ctrl+v # Enter Visual Block mode
: # Enter Command mode
# Without modal editing:
Ctrl+c to copy
Ctrl+v to paste
Mouse to select
Click menu to save
# With Vim:
yy to yank
p to paste
Navigation keys to move
:w to save
# All without leaving the home row
What is the default mode when Vim starts?
Hint: Not insert mode
What key returns you to Normal mode?
Hint: Esc
In Vim, you keep your hands on the home row. No reaching for arrow keys or mouse.
h # Left
j # Down
k # Up
l # Right
w # Word forward
b # Word backward
e # End of word
0 # Start of line
$ # End of line
^ # First non-blank character
gg # First line of file
G # Last line of file
:n # Go to line n
H # High - first line on screen
M # Middle - middle of screen
L # Low - last line on screen
Ctrl+b # Back one screen
Ctrl+f # Forward one screen
Ctrl+d # Down half screen
Ctrl+u # Up half screen
zt # Current line at top
zz # Current line at middle
zb # Current line at bottom
f # Find character forward
F # Find character backward
t # Till character (before)
T # Till character (after)
; # Repeat last f/F/t/T
, # Repeat in opposite direction
What key moves you down a line?
Hint: Not k
What command goes to the end of the file?
Hint: Capital G
Once you know navigation, you need to know how to actually type text.
i # Insert before cursor
I # Insert at beginning of line
a # Append after cursor
A # Append at end of line
o # Open line below
O # Open line above
s # Substitute (delete char + insert)
S # Substitute line (delete line + insert)
c # Change (delete + insert)
Ctrl+h # Delete character before cursor (in insert)
Ctrl+w # Delete word before cursor
Ctrl+u # Delete to beginning of line
Ctrl+o # Temporary Normal mode - one command then back
# e.g., Ctrl+o $ goes to end of line, then back to insert
Ctrl+t # Indent current line
Ctrl+d # Un-indent current line
Esc # Go back to Normal mode
Ctrl+c # Also exits (like Esc)
Ctrl+[ # Also exits (Alt+[)
What command inserts at the end of the current line?
Hint: Capital A
What command opens a new line below?
Hint: Small o
Deleting in Vim doesn't just delete - it cuts into the register for pasting.
x # Delete character under cursor
X # Delete character before cursor
d # Delete operator (needs motion)
dd # Delete entire line
D # Delete to end of line
# With motions:
dw # Delete word
d$ # Delete to end of line
d0 # Delete to beginning of line
dG # Delete to end of file
dgg # Delete to beginning of file
c # Change operator (delete + enter insert)
cc # Change entire line
C # Change to end of line
cw # Change word
c$ # Change to end of line
# Operator + Motion = Action
# operator {motion}
d{ motion } # delete
c{ motion } # change
y{ motion } # yank
# Examples:
dw # delete word
de # delete to end of word
dw # delete word (from cursor to space)
d2w # delete 2 words
d} # delete to end of paragraph
What does dd do?
Hint: Not delete character
What is the operator for change?
Hint: Not d
Yanking is Vim's copy command. It copies text into a register for later pasting.
y # Yank operator (needs motion)
yy # Yank entire line
Y # Yank to end of line (same as y$)
# With motions:
yw # Yank word
y$ # Yank to end of line
y0 # Yank to beginning of line
yG # Yank to end of file
p # Paste after cursor
P # Paste before cursor
# Line operations:
dd # Delete line (cuts it)
p # Paste below
P # Paste above
"a # Use register a
"b # Use register b
# Yank to register a:
"ayy # Yank line to register a
"ap # Paste from register a
# Special registers:
"" # Default register (last yank/delete)
"0 # Yank register (only yanks)
"1 # Most recent delete
:reg # Show all registers
What command yanks (copies) text?
Hint: Like yank
What does p do in Vim?
Hint: After cursor
Vim has powerful search built in.
/pattern # Search forward for pattern
?pattern # Search backward for pattern
n # Next match (same direction)
N # Next match (opposite direction)
# Search within current line:
f # Find char forward
F # Find char backward
t # Till char (stop before)
T # Till char (stop after)
; # Repeat last f/F/t/T
, # Repeat opposite
:s/old/new/ # Replace first match on line
:s/old/new/g # Replace all on line
:%s/old/new/ # Replace first match in file
:%s/old/new/g # Replace all in file
:%s/old/new/gc # Replace all with confirm
# Case sensitive by default
:set ignorecase # Make searches case insensitive
:set noignorecase # Back to case sensitive
. # Any character
* # Zero or more of previous
+ # One or more of previous
\w # Word character
[abc] # Any of a, b, or c
[^abc] # Not a, b, or c
^ # Start of line
$ # End of line
What searches forward in Vim?
Hint: Forward slash
What command replaces all matches in file?
Hint: With %s
Visual mode lets you select text for operations.
v # Visual mode (character-wise)
V # Visual Line mode (line-wise)
Ctrl+v # Visual Block mode (column-wise)
# After selecting:
d # Delete selection
y # Yank selection
c # Change selection (delete + insert)
> # Indent selection
< # Un-indent selection
~ # Toggle case
# In Visual Line mode:
J # Join selected lines
u # Make lowercase
U # Make uppercase
# Select a column:
Ctrl+v # Enter visual block
jjj # Move down (select column)
I # Insert before (in visual block mode)
type text # Type what you want
Esc # Exit - text appears in all lines!
What selects by lines?
Hint: Capital V
What selects columns (vertical)?
Hint: Visual block
Macros let you record a sequence of commands and replay them.
q # Start recording to register (a-z)
... # Do your commands
q # Stop recording
# Play back:
@ # Play macro from register
@@ # Repeat last macro
10@ # Play macro 10 times
# Add quotes around each word on a line:
# Starting with: hello world test
qa # Start recording to register a
b # Move to beginning of word
i # Insert mode
" # Type quote
Esc # Back to normal
e # Move to end of word
a # Append
" # Type quote
Esc # Back to normal
w # Next word
q # Stop recording
# Now apply to each word:
3@a # Run macro 3 times
# Result: "hello" "world" "test"
:reg a # See what's in register a
"ap # Paste contents of register a
# Useful registers:
q # q is good for temporary macros
a # a-z for different macros
0 # yank register persists
What starts recording a macro?
Hint: Then register name
What replays a macro?
Hint: @ then register
Vim can show multiple files or parts of the same file side by side.
:sp file # Split horizontally
:vsp file # Split vertically
Ctrl+ws # Split window horizontally
Ctrl+wv # Split window vertically
# Or open file in split:
:sp filename
:vsp filename
Ctrl+w h # Move to left window
Ctrl+w j # Move to below window
Ctrl+w k # Move to above window
Ctrl+w l # Move to right window
Ctrl+w w # Cycle through windows
Ctrl+w t # Move to top-left window
Ctrl+w p # Move to previous window
Ctrl+w = # Equalize window sizes
Ctrl+w _ # Maximize height
Ctrl+w | # Maximize width
Ctrl+w + # Increase height
Ctrl+w - # Decrease height
:close # Close current window
:only # Keep only current window
What splits vertically?
Hint: :vsp
What cycles through windows?
Hint: w w
Every file you open goes into a buffer. Windows show buffers. Tabs organize windows.
:e file # Edit file (opens in current window)
:badd file # Add file to buffer list
:ls # List all buffers
:bn # Next buffer
:bp # Previous buffer
:bf # First buffer
:bl # Last buffer
:b n # Go to buffer n
:bd # Delete buffer (close file)
:tabnew # New tab
:tabe file # Open file in new tab
:tabn # Next tab
:tabp # Previous tab
:tabfirst # First tab
:tablast # Last tab
gt # Next tab (normal mode)
gT # Previous tab (normal mode)
{n}gt # Go to tab n
# In tabs:
:tabclose # Close tab
:tabdo cmd # Run command in all tabs
Buffer: The file in memory (hidden)
Window: A view onto a buffer
Tab: A collection of windows
What shows all open files?
Hint: List buffers
What command creates a new tab?
Hint: :tabnew
Your .vimrc is where you configure Vim to your liking.
" ~/.vimrc
" Basics
set nocompatible " Use Vim settings, not Vi
set number " Show line numbers
set relativenumber " Relative line numbers
set cursorline " Highlight current line
set showmode " Show current mode
" Search
set ignorecase " Case insensitive search
set smartcase " Case sensitive if caps used
set incsearch " Incremental search
set hlsearch " Highlight searches
" Indentation
set expandtab " Use spaces instead of tabs
set tabstop=4 " Tab = 4 spaces
set shiftwidth=4 " Auto-indent = 4 spaces
set autoindent " Keep indent on new line
set smartindent " Smart auto-indent
" Map leader to space
let mapleader = " "
" Better window navigation
nnoremap h h
nnoremap j j
nnoremap k k
nnoremap l l
" Move lines up/down
vnoremap J :m '>+1gv=gv
vnoremap K :m '<-2gv=gv
" Install vim-plug first
" https://github.com/junegunn/vim-plug
call plug#begin('~/.vim/plugged')
Plug 'tpope/vim-surround'
Plug 'preservim/nerdtree'
Plug 'vim-airline/vim-airline'
call plug#end()
What file stores Vim configuration?
Hint: Dot file
What setting shows line numbers?
Hint: set ???
Vim's plugin ecosystem makes it infinitely extensible.
# vim-plug (popular)
call plug#begin('~/.vim/plugged')
Plug 'author/plugin'
call plug#end()
# Then run:
:PlugInstall
# lazy.nvim (modern, for Neovim)
# packer.nvim (Neovim)
# Vundle (older but works)
" File navigation
Plug 'preservim/nerdtree' " File tree explorer
Plug 'junegunn/fzf.vim' " Fuzzy finder
" Text objects
Plug 'tpope/vim-surround' " cs"', "ysiw", etc.
Plug 'vim-scripts/ReplaceWithRegister'
" Completion
Plug 'neoclide/coc.nvim' " Language server
" Interface
Plug 'vim-airline/vim-airline' " Status bar
Plug 'itchyny/lightline.vim' " Alternative status bar
" Change surrounding
cs"' " Change " to '
cs( " Change ( to (
cs[{ " Change { to [
" Add surrounding
ysiw" " Add " around word
ysiw( " Add ( around word
ys$ " Add to end of line
" Delete surrounding
ds" " Delete " around text
ds( " Delete ( around text
What plugin manages surrounding characters?
Hint: vim-surround
What is a popular plugin manager?
Hint: Run :PlugInstall