Vi editor is a powerful and versatile text editor that has been around for over four decades. It is a command-line based editor that is widely used by programmers, system administrators, and other professionals who work with text files on Unix and Linux systems.
Vi editor is known for its speed, efficiency, and flexibility. It allows users to edit text files of any size, navigate through them quickly, and perform complex editing tasks with ease. Vi editor is also highly customizable, with a wide range of options and settings that can be tailored to suit individual preferences and workflows.
Basic Navigation
Command
Description
h
Move cursor left
j
Move cursor down
k
Move cursor up
l
Move cursor right
0
Move cursor to beginning of line
$
Move cursor to end of line
gg
Move cursor to beginning of file
G
Move cursor to end of file
:n
Move cursor to line number n
Inserting and Editing Text
Command
Description
i
Insert text before cursor
a
Append text after cursor
o
Open new line below cursor
O
Open new line above cursor
r
Replace character under cursor
x
Delete character under cursor
dd
Delete current line
yy
Yank (copy) current line
p
Paste yanked text after cursor
u
Undo last change
Ctrl + r
Redo last change
Searching and Replacing
Command
Description
/pattern
Search for pattern
n
Move to next search result
N
Move to previous search result
:%s/old/new/g
Replace all occurrences of old with new
:s/old/new/g
Replace first occurrence of old with new on current line
:s/old/new/gc
Replace first occurrence of old with new on current line, with confirmation
Saving and Quitting
Command
Description
:w
Save changes
:wq or :x
Save changes and quit
:q
Quit (only if no changes have been made)
:q!
Quit without saving changes
Advanced Navigation
Command
Description
f<char>
Move cursor to next occurrence of <char> on current line
F<char>
Move cursor to previous occurrence of <char> on current line
t<char>
Move cursor to just before next occurrence of <char> on current line
T<char>
Move cursor to just after previous occurrence of <char> on current line
;
Repeat last f, F, t, or T command
,
Repeat last f, F, t, or T command in opposite direction