Vim Editor in Linux (original) (raw)

Last Updated : 14 Jan, 2026

Vim, short for Vi IMproved, is a highly configurable text editor designed for efficient text editing. It is an enhanced version of the Vi editor, which was originally developed in the 1970s. Vim is widely used by programmers, system administrators, and users who spend a significant amount of time working in the terminal.

**Installation and Configure Vim in Our Linux System

Most Linux distributions come with Vim pre-installed. However, if it's not available on your system, you can install it using your package manager. For instance, on Ubuntu or Debian, you can use:

sudo apt-get install vim

To install vim on an arch-based distro run the following command:

sudo pacman -S vim

Now vim will be installed on your system.

Modes in Vim:

One of the most important features of Vim is its modal editing. Vim operates in different modes, each designed for a specific purpose:

Basic Commands in Vim:

Here are some basic commands to get you started:

**Deletion Commands in Vim:

Always use the Esc key to go into normal mode and use the insertion, deletion keys, and other keys.

To **delete the word move the cursor to the beginning of the word and use dw command in normal mode. The word under the cursor will be deleted.

dw

To delete more than one word in a single line use the following command.

To delete 2 words use the command

d2w

To **delete the line move cursor to the beginning of the line and use d$ command in normal mode. The line under the cursor will be deleted.

d$

**Undo and Redo:

As we are programmers most time we are using undo and redo .vim to provide these to both features in it. To undo press u key in normal mode

u

To redo use the ctrl+r key in normal mode in vim

ctrl+r

**Search in Vim Editor

To search the word After the cursor uses the backslash key and then write the word and press enter.

:/word

Use n to move on next matching word

:n

Use N to move on previous matching word

:N

**Search and Replace in Vim Editor

To replace the word in file use s/ command in vim like

:s/searchword/replaceword/

To do replace all occurrence of word use g

:s/searchword/replaceword/g

This command will replace the word globally.

To confirm before replacements of words use gc.

:s/searchword/replaceword/gc

To use this command in the whole file use % before the command.

:%s/searchword/replaceword/gc

Pratical Implementation of Command in Vim Editor

**You can open vim by running vim command on the terminal.

vim

vim window

There are some commands given to use the vim editor. You can see all commands, and it's documentation by help command as follows:

:help

Now to exit type this command

:q!

vim help

Now, Let's Start to use Vim

To open a file in vim editor just write the file name after the vim command in the terminal as follows:

vim filename.txt

Then the file will be opened.

**Write into file

In the previous step we have opened the file now, Let's write some content in to write data we need to go in insert mode. To go into write mode type i. As follows:

i

After going into insert mode you will see INSERT in the status bar. After that, we can write any data in it.

vim window

**Save and Exit:

We have written the data into a file now the task is to save and exit the file to do that first exit from insert mode by pressing the Esc key. To write a command first type semicolon ( ****:** ) and then type the command wq! or x! (both do the same thing) And then hit ENTER.

:wq!

vim window for save and exit

**Exit without saving thefile:

To exit from the file without saving the file just use the command q! As follows

:q!

Vim also comes with its own tutorial. You can see this tutorial by command vimtutor into the terminal .

vimtutor

vim window for save and exit

Now vim tutorial will be opened as follows:

vim window for save and exit

**Text Editing: Insertion

We have edited some text files before by using the i key. There are Four keys used for the insertion of text. Just type the key into the normal mode in vim.

**Motion: Motions provide context to your Operators. These execute the action in a particular way.

Here is a list of some motions

Motions can be combined with operators like d (delete).

**Count: Count is the number for which replete the motion for count number. Here is a demonstration of the use of count and motion

To move courser 2 words forward use the following command

2w

Here 2 is the number of counts and w is used for word

To move the cursor 4 lines forward use the following command

4$