CSC216 Introduction to Programming in C/CPP
Classes

CSC216 Introduction to Programming in C/CPP

Vim Beginners Cheat Sheet

Vim Basics

Starting Vim

Open a file:

Bash
vim hello.c

If the file doesn’t exist, Vim creates it when you save.

The Three Modes

Students struggle because Vim is mode-based.

ModePurpose
NormalNavigation and commands
InsertTyping text
CommandSaving, quitting, searching

When Vim starts, it is in Normal Mode.


Entering Insert Mode

Press

Bash
i

Now type normally.

Leave insert mode with

Bash
Esc

Tell students:

If you ever get lost, press Esc several times.


Saving

Command Mode commands always begin with a colon.

Save:

Bash
:w

Quit

Bash
:q

Save and Quit

Bash
:wq

or

Bash
ZZ

Quit Without Saving

Bash
:q!

Cursor Movement

Instead of arrow keys, Vim traditionally uses

Bash
h   left
j   down
k   up
l   right

Although the arrow keys work, learning these is worthwhile.


Moving Around

Beginning of line

Bash
0

End of line

Bash
$

Beginning of file

Bash
gg

End of file

Bash
G

Next word

Bash
w

Previous word

Bash
b

Delete

Delete one character

Bash
x

Delete one word

Bash
dw

Delete one line

Bash
dd

Delete five lines

Bash
5dd

Undo / Redo

Undo

Bash
u

Redo

Bash
Ctrl-r

Copy and Paste

Copy one line

Bash
yy

Copy five lines

Bash
5yy

Paste below

Bash
p

Paste above

Bash
P

Searching

Search

Bash
/main

Next match

Bash
n

Previous match

Bash
N

Replace

Replace one character

Bash
r

Example

Bash
rx

changes the current character into x.


Join Lines

Bash
J

Indentation

Indent

Bash
>>

Unindent

Bash
<<

Visual Selection

Character mode

Bash
v

Line mode

Bash
V

Block mode

Bash
Ctrl-v

Delete selected text

Bash
d

Copy selected text

Bash
y

Paste

Bash
p

Repeat a Command

The period repeats the last editing command.

Bash
.

Example

Bash
dd
.
.
.

Deletes four consecutive lines.


Multiple Files

Next buffer

Bash
:n

Previous buffer

Bash
:prev

Open another file

Bash
:e filename.c

Helpful Settings

Turn on line numbers

Bash
:set number

Relative numbers

Bash
:set relativenumber

Syntax highlighting

Bash
:syntax on

Help

Bash
:help

Help on a command

Bash
:help dd

Quit help

Bash
:q

Daily Workflow

Bash
vim hello.c

i
    write code

Esc
:w

i
    more editing

Esc
:wq

Commands Students Should Memorize

CommandMeaning
iInsert mode
EscReturn to Normal mode
:wSave
:qQuit
:wqSave and quit
:q!Quit without saving
h j k lMove cursor
ggBeginning of file
GEnd of file
wNext word
ddDelete line
yyCopy line
pPaste
uUndo
Ctrl-rRedo
/textSearch
nNext search result
xDelete character
.Repeat last command

Recommended First Lab (15 minutes)

Have students create a file named hello.c and perform these tasks:

  1. Open hello.c in Vim.
  2. Enter Insert mode and type a simple “Hello, World!” C program.
  3. Save the file (:w).
  4. Move to the top of the file (gg).
  5. Copy the #include line (yy) and paste it below (p).
  6. Delete the duplicate line (dd).
  7. Search for main (/main).
  8. Undo the deletion (u), then redo it (Ctrl-r).
  9. 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.