Mastering Vim: Essential Commands and Plugins
Vim is divisive. Some developers swear by it. Others can’t figure out how to exit.
But there’s a reason Vim has persisted for 27+ years: once mastered, it’s the fastest way to edit text. Here’s how to get there.
Why Vim?
- Speed: Keep hands on home row, no mouse
- Ubiquity: Available on every server
- Composability: Commands combine like language
- Lightweight: Starts instantly, no bloat
- Extensibility: Plugins for everything
The Learning Curve
Week 1: “How do I exit?” Week 2: “This is slow” Week 4: “I’m getting faster” Month 2: “Can’t live without it” Month 6: “Why does VS Code feel slow?”
The discomfort is temporary. The efficiency is permanent.
Modes: The Core Concept
Vim has modes. This is what confuses beginners.
- Normal mode: Navigate and manipulate (default)
- Insert mode: Type text (
i,a,o) - Visual mode: Select text (
v,V,Ctrl-v) - Command mode: Run commands (
:)
Press Esc to return to Normal mode. Always.
Essential Navigation
Character/Word Movement
h j k l - left, down, up, right
w - next word
b - back word
e - end of word
0 - start of line
$ - end of line
^ - first non-space character
Screen Movement
Ctrl-d - half page down
Ctrl-u - half page up
gg - start of file
G - end of file
:42 - go to line 42
Search
/pattern - search forward
?pattern - search backward
n - next match
N - previous match
* - search word under cursor
Editing Commands
The magic of Vim is composability: action + motion.
Basic Actions
d - delete
c - change (delete + insert mode)
y - yank (copy)
p - paste
Combining with Motions
dw - delete word
d$ - delete to end of line
dd - delete line
cw - change word
yy - yank line
Text Objects
diw - delete inner word
daw - delete a word (including space)
di" - delete inside quotes
da( - delete around parentheses
ci{ - change inside braces
Repeat and Undo
. - repeat last command
u - undo
Ctrl-r - redo
Visual Mode Selections
v - character selection
V - line selection
Ctrl-v - block selection
# Then use movements and actions:
Vjjd - select 3 lines and delete
viw - select inner word
Practical Workflows
Quick Fixes
xp - swap two characters
ddp - swap two lines
~ - toggle case
Macro Recording
qa - start recording to register 'a'
(commands)
q - stop recording
@a - play macro
10@a - play macro 10 times
Find and Replace
:s/old/new/ - first occurrence on line
:s/old/new/g - all on line
:%s/old/new/g - all in file
:%s/old/new/gc - all in file, confirm each
Configuration (.vimrc)
Start with sensible defaults:
" ~/.vimrc
" Basics
set nocompatible
syntax on
filetype plugin indent on
" Appearance
set number
set relativenumber
set cursorline
set colorscheme desert
" Indentation
set tabstop=4
set shiftwidth=4
set expandtab
set autoindent
" Search
set incsearch
set hlsearch
set ignorecase
set smartcase
" Quality of life
set clipboard=unnamedplus " Use system clipboard
set mouse=a " Enable mouse
set splitbelow splitright
" Key mappings
let mapleader = " "
nnoremap <leader>w :w<CR>
nnoremap <leader>q :q<CR>
Essential Plugins
Install with a plugin manager like vim-plug:
" ~/.vimrc
call plug#begin('~/.vim/plugged')
Plug 'preservim/nerdtree' " File explorer
Plug 'junegunn/fzf.vim' " Fuzzy finder
Plug 'tpope/vim-fugitive' " Git integration
Plug 'tpope/vim-surround' " Surround with quotes/brackets
Plug 'tpope/vim-commentary' " Comment lines
Plug 'neoclide/coc.nvim' " LSP support
Plug 'airblade/vim-gitgutter' " Git diff in gutter
Plug 'vim-airline/vim-airline' " Status line
call plug#end()
Must-Have Plugins Explained
NERDTree: File explorer
nnoremap <leader>n :NERDTreeToggle<CR>
fzf: Fuzzy file finder
nnoremap <leader>f :Files<CR>
nnoremap <leader>b :Buffers<CR>
nnoremap <leader>g :Rg<CR>
vim-surround: Surround manipulation
cs"' - change " to '
ds" - delete surrounding "
ysiw" - surround word with "
vim-commentary: Comment lines
gcc - comment line
gc - comment selection
Neovim: The Modern Fork
Neovim offers:
- Lua configuration
- Built-in LSP support
- Better plugin architecture
- Async support
Many developers now prefer Neovim for serious development.
Learning Path
- Week 1: hjkl, i/Esc, :wq, basic motions
- Week 2: d, c, y, p, visual mode
- Week 3: Text objects, search/replace
- Week 4: .vimrc customization
- Month 2: Plugins, macros
- Ongoing: Discover new commands as needed
Practice Resources
vimtutor- Built-in tutorial (typevimtutorin terminal)- Vim Adventures - Game-based learning
- Practical Vim - Excellent book
Final Thoughts
Vim rewards investment. The first week is painful. But the long-term efficiency gains are substantial.
Start with basic navigation. Add one new command per day. In a few months, you’ll wonder how you ever used anything else.
Learn once, use everywhere.