VIM

// The killer text editor.

MODAL EDITING IS POWER.

While others scramble for their mouse, you'll be flying through code at the speed of thought. Vim's modal editing lets you manipulate text without ever leaving the keyboard. Every key is a power tool.

ESCAPE THE MOUSE.

Your hands were built for the keyboard, not for hunting and clicking. Vim keeps your fingers on the home row where they belong. Once muscle memory kicks in, you'll wonder how you ever lived without it.

CONFIGURATION IS FREEDOM.

Vim is infinitely configurable. Your .vimrc is your superpower. Customize keybindings, plugins, colorschemesβ€”make it yours. No bloat, no arbitrary restrictions. You control your editor.

BEGIN YOUR JOURNEY β†’

// The Path to Mastery

12 lessons. Total editor dominance.

LESSON 01

Introduction to Vim

Understand modal editing and Vim philosophy

Beginner
LESSON 02

Basic Navigation

Move around with h,j,k,l and word motions

Beginner
LESSON 03

Insert Mode & Text Entry

Enter text and switch between modes

Beginner
LESSON 04

Deleting and Changing

x, d, c commands and the dot operator

Beginner
LESSON 05

Yanking and Pasting

Copy, cut, and paste with registers

Beginner
LESSON 06

Search and Replace

/, n, N, :s for finding and replacing

Beginner
LESSON 07

Visual Mode

Select and manipulate text blocks

Intermediate
LESSON 08

Macros

Record and playback repetitive actions

Intermediate
LESSON 09

Buffers and Windows

Manage multiple files simultaneously

Intermediate
LESSON 10

Splits and Tabs

Master window management

Intermediate
LESSON 11

Advanced Motions

Text objects, folds, and navigation

Advanced
LESSON 12

Vimrc Mastery

Configure and customize your setup

Advanced

// Introduction to Vim

Γ—

What is Vim?

Vim (Vi IMproved) is a modal text editor built into virtually every Unix system. It's been around since 1991 and remains the editor of choice for developers, sysadmins, and anyone who values speed.

Why Vim?

  • Modal Editing: Different modes for different tasksβ€”edit, navigate, select
  • Speed: Once learned, editing becomes incredibly fast
  • Ubiquitous: you'll Available on every server ever touch
  • Extensible: Plugins, custom keybindings, infinite customization
  • Lightweight: Runs in terminal, uses minimal resources
THE VIM PHILOSOPHY: Vim is designed around the idea that repetitive tasks should be automated. Every command can be combined, repeated with the dot operator, and mapped to anything you want.

Installing Vim

$ vim --version VIM - Vi IMproved 9.0

The Modes

Vim has several modes, but you'll use these three most:

  • Normal: The default mode for navigation and commands
  • Insert: For typing and inserting text
  • Visual: For selecting text
# In Vim: i β†’ Enter Insert mode ESC β†’ Return to Normal mode v β†’ Enter Visual mode : β†’ Enter Command mode

Quiz

1. What command takes you from Normal mode to Insert mode?

2. What key do you press to return to Normal mode?

Hint: ESC or Ctrl-[

// Basic Navigation

Γ—

The Core Movement Keys

In Normal mode, these four keys are your compass:

h β†’ Move left j β†’ Move down (looks like an arrow) k β†’ Move up l β†’ Move right
TIP: These keys are on the home row. Keep your fingers here and never reach for the arrow keys again.

Word Motions

w β†’ Jump to start of next word b β†’ Jump to start of previous word e β†’ Jump to end of word W β†’ Jump word (including punctuation) B β†’ Jump back word (including punctuation)

Line and Screen Motions

0 β†’ Jump to beginning of line $ β†’ Jump to end of line ^ β†’ Jump to first non-blank character g_ β†’ Jump to last non-blank character

Screen Motions

H β†’ Jump to top of screen (High) M β†’ Jump to middle of screen L β†’ Jump to bottom of screen (Low) Ctrl+d β†’ Move down half a page Ctrl+u β†’ Move up half a page Ctrl+f β†’ Page forward Ctrl+b β†’ Page backward

Quiz

1. What key moves you to the end of the current word?

2. What command jumps to the end of the line?

// Insert Mode & Text Entry

Γ—

Entering Insert Mode

There are many ways to enter insert mode, each with a different purpose:

i β†’ Insert before cursor 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 β†’ Substitute (delete char and insert) S β†’ Substitute line (delete line and insert) c β†’ Change (combines with motion) cc β†’ Change entire line r β†’ Replace single character R β†’ Replace mode (overwrite)

Leaving Insert Mode

ESC β†’ Exit to Normal mode Ctrl+[ β†’ Exit to Normal mode (alternative) Ctrl+c β†’ Exit to Normal mode
PRO TIP: Remap Caps Lock to Ctrl. You'll hit Ctrl-[ constantly in Vim, and it's much easier when Caps Lock is in the bottom-left corner.

Quiz

1. What command opens a new line BELOW the current line and enters insert mode?

2. What command jumps to the end of the current line and enters insert mode?

Hint: Think "append"

// Deleting and Changing

Γ—

The Delete Commands

In Vim, most commands follow a pattern: operator + motion

x β†’ Delete character under cursor X β†’ Delete character before cursor dw β†’ Delete word d$ β†’ Delete to end of line d0 β†’ Delete to beginning of line dd β†’ Delete entire line 2dd β†’ Delete 2 lines (repeat with number)

The Change Operator

Change is delete + enter insert mode:

cw β†’ Change word (delete word and insert) c$ β†’ Change to end of line cc β†’ Change entire line cb β†’ Change word backward

The Dot Operator

The most powerful command in Vim. Repeats the last change:

. β†’ Repeat last change
EXAMPLE WORKFLOW: 1. Go to a word you want to change 2. Type cw to change the word 3. Type new word 4. Press n to go to next word 5. Press . to repeat the change 6. Press n. repeatedly to change all words

Quiz

1. What does dw do?

2. What does the dot operator (.) do?

// Yanking and Pasting

Γ—

Yank (Copy) Commands

"Yank" is Vim's term for copy:

yy β†’ Yank entire line yw β†’ Yank word y$ β†’ Yank to end of line y0 β†’ Yank to beginning of line p β†’ Paste after cursor P β†’ Paste before cursor

Cut and Paste

In Vim, delete is actually cut (stored in registers):

dd β†’ Cut entire line (can paste with p) x β†’ Cut character (can paste with p) d β†’ Any delete is also a cut

Registers

Vim has 36 registers for storing text:

"ayy β†’ Yank line to register a "ap β†’ Paste from register a "bdd β†’ Cut line to register b "0p β†’ Paste from yank register (0) :reg β†’ View all registers
THE BLACK HOLE REGISTER: Use "_dd to delete a line without saving it to any register. Useful when you want to cut something but not overwrite what you already copied.

Quiz

1. What is Vim's term for copy?

2. What command pastes after the cursor?

// Search and Replace

Γ—

Search Within File

/pattern β†’ Search forward for pattern ?pattern β†’ Search backward for pattern n β†’ Next match (in search direction) N β†’ Previous match (opposite direction) * β†’ Search for word under cursor # β†’ Search backward for word under cursor

Find and Replace

Use the :substitute command:

:s/old/new β†’ Replace first occurrence in line :s/old/new/g β†’ Replace all in line :%s/old/new/g β†’ Replace all in file :%s/old/new/gc β†’ Replace all, confirm each :s/old/new/gI β†’ Replace all, case insensitive

Range Substitutions

:5,12s/old/new/g β†’ Replace in lines 5-12 :.,+5s/old/new/g β†’ Replace in current line + 5 more :'a,'bs/old/new/g β†’ Replace between marks a and b
VERY MAGIC MODE: Use \v for regex: :%s/\v<(\w+)\gt;/\1/g removes duplicate words. Or enable with :set magic

Quiz

1. What command searches forward?

2. What command replaces all occurrences in the file?

// Visual Mode

Γ—

Visual Mode Types

v β†’ Character-wise visual mode V β†’ Line-wise visual mode Ctrl+v β†’ Block-wise visual mode gv β†’ Reselect last visual selection

Visual Mode Commands

Once you've selected text, apply operators:

d β†’ Delete selection c β†’ Change selection y β†’ Yank selection > β†’ Indent right < β†’ Indent left ~ β†’ Toggle case U β†’ Uppercase u β†’ Lowercase

Block Visual Mode

Ctrl+v lets you edit columns:

EXAMPLE: Comment out multiple lines: 1. Ctrl+v to enter block mode 2. Select column with j/k 3. Shift+i to insert 4. Type // 5. ESC to apply to all lines

Quiz

1. What visual mode selects entire lines?

2. What key combo enters block visual mode?

// Macros

Γ—

Recording Macros

Macros record and playback sequences of commands:

qa β†’ Start recording macro to register a q β†’ Stop recording @a β†’ Play back macro from register a @@ β†’ Repeat last macro 10@a β†’ Play macro 10 times

Practical Macro Example

Add brackets around each word on a line:

PROBLEM: Convert "foo bar baz" to "[foo] [bar] [baz]"
# Recording: qa β†’ Start recording to a i[ β†’ Insert [ before word e β†’ Jump to end of word a] β†’ Append ] after word ESC β†’ Exit insert w β†’ Move to next word q β†’ Stop recording 2@q β†’ Run macro 2 more times

Editing Macros

:reg a β†’ View contents of register a "ap β†’ Paste register a (to edit) "ay$ β†’ Yank edited text back to register a

Quiz

1. What command starts recording a macro to register a?

2. What command plays back the last macro?

// Buffers and Windows

Γ—

Buffers

A buffer is a file loaded into memory:

:e filename β†’ Edit file (opens in current window) :badd file β†’ Add file to buffer list :ls β†’ List all buffers :bp β†’ Previous buffer :bn β†’ Next buffer :bfirst β†’ First buffer :blast β†’ Last buffer :bd 3 β†’ Delete buffer 3 :b 3 β†’ Jump to buffer 3

Multiple Windows

A window is a viewport into a buffer:

:sp β†’ Split horizontally :vsp β†’ Split vertically Ctrl+ws β†’ Split window Ctrl+wv β†’ Split window vertically Ctrl+ww β†’ Cycle windows Ctrl+wh β†’ Move to window left Ctrl+wj β†’ Move to window below Ctrl+wk β†’ Move to window above Ctrl+wl β†’ Move to window right :qa β†’ Quit all windows :wqa β†’ Write and quit all

Quiz

1. What is a buffer in Vim?

2. What command splits the window horizontally?

// Splits and Tabs

Γ—

Splits in Detail

:sp file β†’ Split and open file :vsp file β†’ Vertical split and open Ctrl+w_ β†’ Maximize current window Ctrl+w= β†’ Equalize windows 10 Ctrl+w+ β†’ Increase height by 10 10 Ctrl+w- β†’ Decrease height by 10 :resize 50 β†’ Set window height :vertical resize 80 β†’ Set window width

Tabs

Tabs are collections of windows:

:tabnew β†’ New tab :tabe file β†’ Open file in new tab gt β†’ Next tab gT β†’ Previous tab 1gt β†’ Go to tab 1 :tabclose β†’ Close tab :tabonly β†’ Close other tabs :tabmove 0 β†’ Move tab to position 0
TIP: Use tabs for different projects, splits for working on multiple files in the same project. Learn the movement commandsβ€”they're faster than reaching for the mouse.

Quiz

1. What command switches to the next tab?

2. How do you maximize the current window?

// Advanced Motions

Γ—

Text Objects

Text objects let you operate on blocks of text:

iw β†’ Inner word (excluding whitespace) aw β†’ A word (including whitespace) i( β†’ Inner parentheses a( β†’ A parentheses (including parens) i[ β†’ Inner brackets i{ β†’ Inner braces i" β†’ Inner quotes i' β†’ Inner single quotes it β†’ Inner tag (HTML/XML)
COMBINED WITH OPERATORS: ci( = change inside parentheses da" = delete a quoted string (including quotes) yit = yank inner tag

Folds

zf β†’ Create fold (visual mode) zF β†’ Create fold (line-wise) zo β†’ Open fold zc β†’ Close fold za β†’ Toggle fold zR β†’ Open all folds zM β†’ Close all folds zr β†’ Reduce folding zm β†’ More folding

Jumps

Ctrl+o β†’ Go back (jump list) Ctrl+i β†’ Go forward (jump list) Ctrl+] β†’ Jump to tag (e.g., function definition) Ctrl+t β†’ Pop tag (go back) g; β†’ Go to last edit location g, β†’ Go forward in change list :jumps β†’ Show jump list

Quiz

1. What text object selects inside parentheses?

2. What command toggles a fold?

// Vimrc Mastery

Γ—

The Vimrc File

Your .vimrc configures Vim to your taste:

$ vim ~/.vimrc

Essential Settings

" Basic settings set nocompatible β†’ Disable Vi compatibility syntax on β†’ Enable syntax highlighting set number β†’ Show line numbers set relativenumber β†’ Relative line numbers set ai β†’ Auto indent set si β†’ Smart indent set tabstop=4 β†’ Tab width set expandtab β†’ Use spaces instead of tabs set autoindent β†’ Preserve indentation set hlsearch β†’ Highlight search results set incsearch β†’ Incremental search set ignorecase β†’ Case insensitive search set smartcase β†’ Case sensitive if uppercase set wrap β†’ Wrap long lines set cursorline β†’ Highlight current line

Key Mappings

" Remap leader key let mapleader = "," " Faster escape inoremap jk <ESC> inoremap kj <ESC> " Better window navigation nnoremap <C-h> <C-w>h nnoremap <C-j> <C-w>j nnoremap <C-k> <C-w>k nnoremap <C-l> <C-w>l

Plugins

" Install plugin manager curl -fLo ~/.vim/autoload/plug.vim --create-dirs \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
" In .vimrc: call plug#begin('~/.vim/plugged') Plug 'tpope/vim-surround' Plug 'junegunn/fzf' Plug 'scrooloose/nerdtree' call plug#end()

Quiz

1. What setting enables syntax highlighting?

2. What command sets the leader key to comma?