top of page
Recent Posts

vim the powerful text editor tool for linux

Updated: Oct 3, 2021

Document Id: RHEL003

In my previous post, I've shown commonly used Linux commands, in this post I'll describe a powerful text editor which is used to edit Linux configuration text files.

Previous post: Linux basic commands

Vim is a powerful text editor used in CLI (command line interface). It’s available almost all Linux distribution. Linux uses a lot of configuration files, we’ll often use “vim” to edit configuration files.

Using vim we can open an existing text file, then, edit it and save, or we can create a newfile, edit the file and save & exit.

There are two modes in vim editor

1. Command Mode

In this mode we can apply commands like cut, copy, paste, search, undo, save, exit, etc

2. Insert mode

In this mode, we can insert/edit text.

Initially “vim” open in command mode to switch insert mode we have to press “i” from keyboard.

From command mode to insert mode press “i”

From insert mode to command mode press”Esc”

Let’s create a new file using vim

[root@RHEL82 ~]# vim fileA

The file has been created in system memory and opened in command mode, now if we want to exit from the vim we can press:q! (colon,q,! together)

:q! is used for exit from vim editor without saving the file.

Now let’s check the fileA

[root@RHEL82 ~]# ls

We see that there is no file name “fileA” because we exit from “vim” editor without saving the file, so fileA has not been created in the disk.

If we want to create a new file using “vim” we must do"save & exit" then only it will create a file in the disk.

Let’s create the fileA again, input text then save & exit

[root@RHEL82 ~]# vim fileA

It is in command mode, to change command mode to insert mode press “i”

Now, Add text “ This is RedHat Enterprise Linux 8.2”

Press” Esc” to return command mode

To save & exit command is :wq (colon,w,q together) then press "Enter" key.