Vim Beginners Cheat Sheet
Vim Basics
Starting Vim
Open a file:
vim hello.cIf the file doesn’t exist, Vim creates it when you save.
The Three Modes
Students struggle because Vim is mode-based.
| Mode | Purpose |
|---|---|
| Normal | Navigation and commands |
| Insert | Typing text |
| Command | Saving, quitting, searching |
When Vim starts, it is in Normal Mode.
Entering Insert Mode
Press
iNow type normally.
Leave insert mode with
EscTell students:
If you ever get lost, press Esc several times.
Saving
Command Mode commands always begin with a colon.
Save:
:wQuit
:qSave and Quit
:wqor
ZZQuit Without Saving
:q!Cursor Movement
Instead of arrow keys, Vim traditionally uses
h left
j down
k up
l rightAlthough the arrow keys work, learning these is worthwhile.
Moving Around
Beginning of line
0End of line
$Beginning of file
ggEnd of file
GNext word
wPrevious word
bDelete
Delete one character
xDelete one word
dwDelete one line
ddDelete five lines
5ddUndo / Redo
Undo
uRedo
Ctrl-rCopy and Paste
Copy one line
yyCopy five lines
5yyPaste below
pPaste above
PSearching
Search
/mainNext match
nPrevious match
NReplace
Replace one character
rExample
rxchanges the current character into x.
Join Lines
JIndentation
Indent
>>Unindent
<<Visual Selection
Character mode
vLine mode
VBlock mode
Ctrl-vDelete selected text
dCopy selected text
yPaste
pRepeat a Command
The period repeats the last editing command.
.Example
dd
.
.
.Deletes four consecutive lines.
Multiple Files
Next buffer
:nPrevious buffer
:prevOpen another file
:e filename.cHelpful Settings
Turn on line numbers
:set numberRelative numbers
:set relativenumberSyntax highlighting
:syntax onHelp
:helpHelp on a command
:help ddQuit help
:qDaily Workflow
vim hello.c
i
write code
Esc
:w
i
more editing
Esc
:wqCommands Students Should Memorize
| Command | Meaning |
|---|---|
| i | Insert mode |
| Esc | Return to Normal mode |
| :w | Save |
| :q | Quit |
| :wq | Save and quit |
| :q! | Quit without saving |
| h j k l | Move cursor |
| gg | Beginning of file |
| G | End of file |
| w | Next word |
| dd | Delete line |
| yy | Copy line |
| p | Paste |
| u | Undo |
| Ctrl-r | Redo |
| /text | Search |
| n | Next search result |
| x | Delete character |
| . | Repeat last command |
Recommended First Lab (15 minutes)
Have students create a file named hello.c and perform these tasks:
- Open
hello.cin Vim. - Enter Insert mode and type a simple “Hello, World!” C program.
- Save the file (
:w). - Move to the top of the file (
gg). - Copy the
#includeline (yy) and paste it below (p). - Delete the duplicate line (
dd). - Search for
main(/main). - Undo the deletion (
u), then redo it (Ctrl-r). - Save and quit (
:wq).
This sequence reinforces the core commands students will use throughout the semester without introducing advanced features too early. Once they’re comfortable with these basics, you can add topics like split windows, multiple buffers, macros, and plugins in later lessons.
