Mastering Vim: Essential Commands and Plugins

productivity dev vim

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?

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.

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
/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:

Many developers now prefer Neovim for serious development.

Learning Path

  1. Week 1: hjkl, i/Esc, :wq, basic motions
  2. Week 2: d, c, y, p, visual mode
  3. Week 3: Text objects, search/replace
  4. Week 4: .vimrc customization
  5. Month 2: Plugins, macros
  6. Ongoing: Discover new commands as needed

Practice Resources

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.

All posts