How to edit files with vi or vim command

Windows Articles

How to install KVM on Debian 10?

Hello friends, in this post I will show you how to install KVM on Debian 10. KVM stands for...

How to open Windows 10 Mobility Center

Hello! There are many types of users of Windows 10. As it depends on the type of hardware used. That is, the...

Ubuntu 20.04.1 available

Canonical, the company led by Mark Shuttleworth, releases Ubuntu 20.04.1. It has a new image, with updates and security patches for the...

How to install Linux Kernel 5.8 on Ubuntu 20.04?

Upgrading the Linux Kernel can be a beneficial task, but it is always optional. Recently we talked about the Linux Kernel 5.8...

How to activate XPS Viewer in Windows 10

Hey, what's up! When working with Windows 10 we probably use a lot of files. Indeed, these files have many extensions. For...
Muhammad Nabeel
Muhammad Nabeel
Network and System Administrator

What is vim?

Vim is a clone, with additions, of Bill Joy’s vi text editor program for Unix. vi/vim used to edit or modify a text files in CLI (Command Line Interface).

It is most popular text editor in Linux. Today, we will discus its usage and option.

Vi or Vim has three modes

Escape or Normal mode
Insert mode press i to insert
Replace mode

In this example i will use /etc/hosts file for vim command. Simply, run below command and you will get into normal mode.

vim /etc/hosts

Now, if you want to edit your file. You need to go on insert mode. Press “i” for insert mode and now you can add text in the file.

After adding your text, Press “Esc” key to switch back to normal mode.
Now save and exit file by typing : x OR :wq and press “enter” key

So, you can move around with the arrow keys, or by using the vi movement keys, as follows:
h left
j down
k up
l right

vim options for Escape/Normal mode

:w save changes to file.
:wq save and exit from file.
: x save and exit from file.
:q! Exit without saving.
i so i use to insert where is the cursor.
o cursor will move to next line to insert.
x Delete the character the cursor is on.
Shift+x Delete the character before the cursor.
dd Delete the current line, also used for delete.


Shift+d Delete everything from the cursor to the end of the line.
u Undo a line you just deleted.
Shift+u Undo all changes to the current line.
yy Copy current line.
p past copied line or text.
y4 Copy multiple lines. 4 is the number of lines we want to copy.
/string-name to search desired text. String name is the text we want to search.
n Move to next searched string.
shft+n move to to previous searched string.


:%s/old-string/new-string/g Replace old text with new text.
:9 To go line no. 9
gg Go on the top of file.
shft+g Go to the end of file.
Ctrl+b Go back one page.
Ctrl+f Go forward one page.

That’s it. Practice all above options to get grip on vim command.

More articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest article

How to install KVM on Debian 10?

Hello friends, in this post I will show you how to install KVM on Debian 10. KVM stands for...

How to open Windows 10 Mobility Center

Hello! There are many types of users of Windows 10. As it depends on the type of hardware used. That is, the...

Ubuntu 20.04.1 available

Canonical, the company led by Mark Shuttleworth, releases Ubuntu 20.04.1. It has a new image, with updates and security patches for the...

How to install Linux Kernel 5.8 on Ubuntu 20.04?

Upgrading the Linux Kernel can be a beneficial task, but it is always optional. Recently we talked about the Linux Kernel 5.8...

How to activate XPS Viewer in Windows 10

Hey, what's up! When working with Windows 10 we probably use a lot of files. Indeed, these files have many extensions. For...