1.
Switching Modes
Command: i, a, o, Esc
i: Enters Insert Mode at the cursor's current position.
Example: If your cursor is on the t in "text" and you press i, you can start typing before the t.
a: Enters Insert Mode after the cursor.
Example: If your cursor is on the t in "text" and you press a, typing starts after the t.
o: Opens a new line below the current line and enters Insert Mode.
Example: If your cursor is on a line with "text", pressing o creates a blank line below it.
Esc: Exits Insert Mode back to Command Mode.
Example: After typing text in Insert Mode, press Esc to save your position.
2. Saving and Exiting
Command: :w, :q, :wq, :q!
:w: Saves the file.
Example: After editing, type :w and press Enter to save the changes.
:q: Quits if no changes were made.
Example: If you’ve only viewed the file, type :q and press Enter to exit.
:wq or :x: Saves and exits the file.
Example: After editing, type :wq or :x and press Enter.
:q!: Quits without saving changes.
Example: If you accidentally made changes and want to exit, type :q!.
3. Navigation
Command: h, l, k, j, 0, $, G, nG
h, l, k, j:
Navigate left, right, up, and down.
Example: Press j to move to the next line.
0: Moves to the beginning of the line.
Example: If your cursor is in the middle of a line, press 0 to go to the start.
$: Moves to the end of the line.
Example: If your cursor is at the start of a line, press $ to go to the end.
G: Moves to the last line of the file.
Example: Quickly reach the bottom by pressing G.
nG: Moves to the nth line.
Example: Type 10G to jump to line 10.
4. Editing
Command: x, dd, D, u, r
x:Deletes the character under the cursor.
Example: If your cursor is on the e in "text" and you press x, it deletes the e.
Prof. (Dr.) Ajay Kr. Singh Page 1|2
dd: Deletes the entire current line.
Example: If your cursor is anywhere on the line "Delete me", pressing dd removes the line.
D: Deletes from the cursor to the end of the line.
Example: If your cursor is in the middle of "Hello, World!" and you press D, it deletes everything after
the cursor.
u: Undoes the last change.
Example: If you accidentally delete a line with dd, pressing u restores it.
r: Replaces a single character.
Example: If the cursor is on e in "text" and you press r followed by o, "text" becomes "toxt".
5. Search
Command: /pattern, n, N
/pattern: Searches forward for "pattern".
Example: To search for the word "hello", type /hello and press Enter.
n: Repeats the search in the same direction.
Example: After searching for "hello", pressing n finds the next occurrence.
N: Repeats the search in the opposite direction.
Example: If you used /hello and pressed N, it searches upward instead of downward.
6. Copy, Cut, and Paste
Command: yy, dd, p, P
yy: Copies (yanks) the current line.
Example: If your cursor is on "Copy me" and you press yy, the line is copied.
dd: Cuts the current line.
Example: If your cursor is on "Cut me" and you press dd, the line is removed.
p: Pastes after the cursor.
Example: After copying or cutting, press p to paste below the cursor.
P: Pastes before the cursor.
Example: After copying or cutting, press P to paste above the cursor.
7. Replace Text
Command: :%s/old/new/g
:%s/old/new/g: Replaces all occurrences of "old" with "new".
Example: Replace "foo" with "bar" in the entire file using :%s/foo/bar/g.
Prof. (Dr.) Ajay Kr. Singh Page 2|2