A Cypherpunk’s Blog

Just a simple minimalist blog of a cypherpunk wannabe.

VIM

Vim Cheatsheet

Basics

  • vim filename — Open a file in Vim
  • :q — Quit Vim
  • :q! — Quit without saving
  • :w — Save file
  • :wq or :x — Save and quit
  • i — Enter insert mode
  • Esc — Exit insert mode and return to normal mode

Movement

  • h — Move left
  • j — Move down
  • k — Move up
  • l — Move right
  • 0 — Move to beginning of line
  • ^ — Move to first non-blank character of line
  • $ — Move to end of line
  • gg — Go to beginning of file
  • G — Go to end of file
  • w — Jump forward to next word
  • b — Jump backward to previous word
  • Ctrl + d — Scroll half page down
  • Ctrl + u — Scroll half page up

Editing

  • x — Delete character under cursor
  • dd — Delete current line
  • yy — Yank (copy) current line
  • p — Paste after cursor
  • u — Undo
  • Ctrl + r — Redo
  • r<char> — Replace character under cursor with <char>
  • cw — Change word
  • C — Change to end of line

Searching and Replacing

  • /pattern — Search for pattern forward
  • ?pattern — Search for pattern backward
  • n — Repeat last search forward
  • N — Repeat last search backward
  • :%s/old/new/g — Replace all occurrences of “old” with “new” in file

Visual Mode

  • v — Start visual mode (select text)
  • V — Start linewise visual mode
  • Ctrl + v — Start block visual mode

Buffers and Files

  • :e filename — Open another file
  • :bnext or :bn — Switch to next buffer
  • :bprev or :bp — Switch to previous buffer
  • :bd — Close current buffer

Window Management

  • :split or :sp — Horizontal split
  • :vsplit or :vsp — Vertical split
  • Ctrl + w + h/j/k/l — Move between windows

Exiting

  • :wq — Save and quit
  • :q! — Quit without saving

Note: Use Esc to switch back to Normal mode from Insert or Visual mode.