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.
We will start by opening a text file by providing the name of the file. In this example we will open the file named
$ vi poem.txt
After opening the
vi editor we will be in the command mode. Command mode will enable
vi shortcuts like
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.
We can enter to the command mode again with the
Esc or Escape. This will return from the Insert Mode to the Command mode.
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.
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.
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.
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 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
Quit without Saving
If we made some changes but do not want to save them and preserve the original file we can use