How to use VIM editor on Linux

In this segment we will take a look at a tool to put content into files and edit that content also. Vi (Vim) is a very incredible tool. The aim of this article is not to cover everything that Vi can do however to get you ready for the basics.

Vi is a command line text editor, the command line is a different environment. It’s a single window with text input and output only. Let’s jump into it and try to learn the basics stuff about Vim.

A. Normally vim is run with a single argument which is the file you would like to edit. When we specify the file it can be with either file name or file path. Vi and Vim, both can be used. You can do it this way. The file will be empty.

Start VIM on linux
VIM editor linux

B. Vim generally starts in EDIT mode so the first thing we will do is switch to INSERT mode by typing “i”.

start VIM editor

You can type in a couple of lines of text and press Esc which will return to EDIT mode.

ESC

Let’s try some more advanced steps. For these, ensure you are in EDIT mode.

If you are not sure that you are in EDIT mode or not, you can take a look at the bottom left corner. If it does not say INSERT, you are fine or you can simply press Esc to exit INSERT mode. If you are in Edit mode, pressing Esc does nothing.

C. Suppose you want to quit and discard all the changes to the file. The option (:q!) can be used. First press colon (:) and then type “q!”. Make sure you are not in INSERT mode.

discard all the changes

D. Suppose you want to save a file but do not want to exit. The option (:w) can be used. You can do it this way.

exit

E. Suppose you want to save a file but also want to exit. The option (:wq) can be used. You can do it in this way.

want to exit

F. Suppose you want to move around the cursor at a specific point in the file, arrow keys can be used and you can do your things according to EDIT or INSERT MODE.

INSERT MODE

G. Suppose you want to give numbers to the lines, “set number” command can be used.

set number

H. Suppose you want to delete the content of the file, there are commands for this but “backspace” and “delete” are easy to use, those options can be used in INSERT mode.

delete content of the file

I. Suppose you want to search for a particular word in a file, there are different ways to do this but in vim it can be done using “/yourword” syntax, vim will highlight the line in which the word is present.

you want to search for a particular word in a file

J. Suppose you want to replace every occurrence of a word with a replacement word in a file, it can be done using “%s/pattern/replace/g”.

replace every occurrence

Few more important commands are mentioned below.

Commands for VIM

For more options, See the Manual Page.

More on Related Topics :

1. Understanding the History, Versions, and Main Components of UNIX

2. How to Disable IPv6 Leak on Linux ?

3. Understanding the System Startup and Remote Login in UNIX

4. How to use rm and rmdir commands in Linux ?

Biplab Das

Biplab Das

My name is Biplab Das. I’m a writer, Blogger, Youtuber and full time IT support engineer whose childhood obsession with science fiction never quite faded. A quarter-century later, the technology that I coveted as a kid is woven into the fabric of everyday life. I’ve spent the past years to learn these technologies, I recently published a book on computer science fundamentals. People say smartphones are boring these days, but I think everyone is beginning to take this wonderful technology marvel for granted.
Keep Digging Technology.

Sign up for our Newsletter

Sign Up for our Newsletter for daily Updates !

shares