vi is a primary text editor in Linux. This is not a normal test editing tool. vi has a lot of commands and modes.
vi / vim text editor (or) vi command in linux
![]() |
vi (or) vim text editor |
what is vi / vim?
'vi' is a primary text editor you can perform many operations using this editor, Let's see.
create a file
By default, You will be in the command mode. In this mode, you are able to perform a set of operations.
This tilde (~) symbol represents a new line.
In the end, it displays the file name.
change to insert mode
![]() |
Insert mode |
Just press i
Press "i" to enable insert mode.
![]() |
Text editing |
To exit insert mode press the "Esc" key. And it will be in the command mode.
To delete the current line
dd
- Move the cursor to the line which you want to delete.
- press "dd" key to delete the current line.
undo changes
u (small letter)
- If you want to undo your edits.
- Press "u" to undo changes.
redo
. (dot)
- Press "." (dot) to redo.
copy current line
yy
- press "yy" to copy the current line.
paste
P (capital letter)
- press capital "P" to paste above the current line.
p (small letter)
- press small "p" to paste below the current line.
To delete a single character
x (small letter)
- move the cursor to the character.
- press "x" key to delete a single letter.
To delete a single word
dw
- move the cursor to the word.
- press "dw" to delete a word.
Beginning of the next word
w (small letter)
- If you want to move the cursor to the beginning of the next word.
- press the "w" key.
- which moves the cursor to the beginning of the next word.
Beginning of the previous word
b
- press "b" key.
- To move the cursor to the beginning of the previous word.
Move the cursor beginning or end of the paragraphs
{
- press "{" symbol.
- To move the cursor to the beginning of the paragraphs.
}
- To move the cursor to the end of the paragraphs.
Move the cursor to the beginning or end of the line
0 (or) Home key
- press "0" or "Home" key.
- To move the cursor to the beginning of the line.
$ (or) End key
- To move the cursor to the end of the line.
Go to Begining or end of the file
Shift+G (or) Ctrl+Home
- press "Shift+G" or "Ctrl+Home".
- To move the cursor to the beginning of the file.
Shift+H (or) Ctrl+End
- Move the cursor to the end of the file.
Appending lines
a
- press "a" key.
- To append text after the current cursor position.
A
- The cursor will move to the end of the current line in the Insert mode.
o (small letter)
- The cursor will move to the new line below the current line in the insert mode.
O (capital letter)
- The cursor will move to the new line above the current line in the Insert mode.
Execute mode
:
- Press : (colon) key.
- To enter into execute mode.
Save Files
:w
- To save your file.
Note:
You must save your file before exit because every change you made is automatically saved in a buffer until you save your files.
Quit
:q (or) :x
- To quit a saved file.
Force Quit
:q!
- To quit a file without saving.
Set line number
:set nu
- This will add a number at the beginning of each line.
Move the cursor using line number
:(line number)
- Press ":" and line number.
- To move the cursor at that line.
Replace a word
![]() |
Replace a word |
:%s/current word/replacement word
- To replace a word.
Conclusion
These are the basic commands in vi editors. Note that these commands are case sensitive i.e) the capital letter is different from the small letter.
HAVE A NICE DAY 💓