How To Use Vi Editor?

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/how-to-use-vi-editor/
PINTEREST
PINTEREST
INSTAGRAM

vi is very powerful text editor where most of the Linux distributions provides. vim is improved version of the vi editor with more features. Most of the intersecting features complies with vim . In this tutorial we will learn how to use vi from start.

Open File

We will start by opening a text file by providing the name of the file. In this example we will open the file named poem.txt.

Open File
Open File

Insert Mode

After opening the vi editor we will be in the command mode. Command mode will enable vi shortcuts like Copy , Paste , Delete Line etc. If we want to change text we need to enter Insert Mode . By entering i we will enter to the Insert Mode.

Insert Mode
Insert Mode

Command Mode

We can enter to the command mode again with the Esc or Escape. This will return from the Insert Mode to the Command mode.

Copy

There are different commands in the Command Mode. We can copy given line with the yy command like below. This will copy current line.

OR we can specify the number of lines starting from current line which is 5 in this case.

Paste

With yy command given line will be copied to the buffer. We can paste the latest buffer content to the cursor position with the p command like below.

Paste
Paste

Delete Line

We can delete the current line with the dd command. As stated this will only delete current single line. If we want to delete from current line to the down we can provide the line numbers betwee d‘s . In this example we will delete 5 lines from current line.

LEARN MORE  Vi/Vim Show Line Numbers

Delete Line
Delete Line

Save

Over time we will made changes in the current file. These changes should be save after some time in order to prevent loss. We can save current file with the :w  which means save.

Save vi
Save vi

Save and Quit

We can also made some work quicker. We want to save file and then quit. This can be down with a single command :wq

Quit without Saving

If we made some changes but do not want to save them and preserve the original file we can use :q!

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/how-to-use-vi-editor/
PINTEREST
PINTEREST
INSTAGRAM