You are on page 1of 1

Command Mode:

Navigation:

h: Move cursor left


j: Move cursor down
k: Move cursor up
l: Move cursor right
0 (zero): Move to the beginning of the line
$: Move to the end of the line
G: Move to the end of the file
gg: Move to the beginning of the file
:<line number>: Move to a specific line number (e.g., :15)
Editing:

i: Enter insert mode before the cursor


I: Enter insert mode at the beginning of the line
a: Enter insert mode after the cursor
A: Enter insert mode at the end of the line
o: Open a new line below the current line
O: Open a new line above the current line
x: Delete the character under the cursor
dd: Delete the current line
yy: Copy the current line
p: Paste the copied or deleted text after the cursor
P: Paste the copied or deleted text before the cursor
Undo/Redo:

u: Undo the last change


Ctrl + r: Redo the undone change
Search and Replace:

/: Search forward (e.g., /pattern)


?: Search backward (e.g., ?pattern)
n: Move to the next occurrence of the search pattern
N: Move to the previous occurrence of the search pattern
:s/old/new/g: Replace all occurrences of 'old' with 'new' in the current line
:%s/old/new/g: Replace all occurrences of 'old' with 'new' in the entire file
Saving and Quitting:

:w: Save changes


:q: Quit (if no changes)
:wq or ZZ: Save and quit
:q!: Quit without saving changes
Insert Mode:
In insert mode, you can type and edit text as you would in any other text editor.
Exiting Insert Mode:
Press Esc to exit insert mode and return to command mode.
Remember that vi can have a steep learning curve, but it's a powerful editor once
you become familiar with its commands.

You might also like