VIM
Vim Cheatsheet
Basics
vim filename— Open a file in Vim:q— Quit Vim:q!— Quit without saving:w— Save file:wqor:x— Save and quiti— Enter insert modeEsc— Exit insert mode and return to normal mode
Movement
h— Move leftj— Move downk— Move upl— Move right0— Move to beginning of line^— Move to first non-blank character of line$— Move to end of linegg— Go to beginning of fileG— Go to end of filew— Jump forward to next wordb— Jump backward to previous wordCtrl + d— Scroll half page downCtrl + u— Scroll half page up
Editing
x— Delete character under cursordd— Delete current lineyy— Yank (copy) current linep— Paste after cursoru— UndoCtrl + r— Redor<char>— Replace character under cursor with<char>cw— Change wordC— Change to end of line
Searching and Replacing
/pattern— Search for pattern forward?pattern— Search for pattern backwardn— Repeat last search forwardN— 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 modeCtrl + v— Start block visual mode
Buffers and Files
:e filename— Open another file:bnextor:bn— Switch to next buffer:bprevor:bp— Switch to previous buffer:bd— Close current buffer
Window Management
:splitor:sp— Horizontal split:vsplitor:vsp— Vertical splitCtrl + 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.