Hold my beer, #60daysofDevops will make Linux easy.

The VI Editor

Saurav chaudhary
3 min readAug 28, 2021

--

Day 2 Of #6odaysofDevops

Introduction to Vi Editor

There are a number of text editors available in Linux such as vi, vim, Nano etc. but we will focus on vi because it’s the most popular one.

Vi editor comes installed by default in most operating systems. Run the “vi” command and specify the file name to open it e.g. — vi index.html

The terminal opens the file and you’ll now be inside the editor. The vi editor has 3 modes of operation, the command mode ,insert mode and last line mode. When you open a file in the vi editor, you are by default in the command mode and in this mode, you can issue commands such as to copy and paste lines or delete a line or word or to navigate between lines etc. but you can’t write contents to the file. To write contents to the file, you must switch to the insert mode.

Command Mode

Commands to perform actions in command mode like copy ,paste, delete and much more. Now lets learn some commands and try to run these commands on your own

1 ) To move around — Use arrow keys or (K,H,J,L)

2) To copy a line — press y y

3) To paste — press p

4) To delete a letter — press x

5)To delete a line — press d d

6) To delete a specific no of lines let’s say 6 — press d 6 d

7) To Undo — press u

8) To Redo — press r

9) To Find — press /line ?line e.g. to find 6 -/6

10)To find next — press n

11) To find previous — press N

Note -To change mode from command to insert press ( I, O, A , i, o ,a) .

Insert Mode

Once you’re in insert mode, you may modify the file contents as you would normally. you can add text , edit files , Remove text. You may move around the editor using the arrow keys or the keys k, j, h, l. — k to go up, j to go down, h to move left and l to move right. You can insert , delete anything in this mode. You can press “x” to delete a character or type “d d” to delete the entire line. To copy a line, type “y y” and to scroll the page up or down, press Ctrl+u or Ctrl+d.

Note -To change mode from insert to command mode press ( esc ).

Last Line Mode

Typing in colon “:” takes you to Last Line mode.

  1. To Save — press :w
  2. To Quit — press :q
  3. To Save & Quit — press :w q
  4. To Quit Without Confirmation — press :q!

WHAT IS VIM?

Vim stands for Vi Improved. It is an implementation of the Vi standard with many additions. It is the most commonly used implementation of the standard. Most Linux distributions come with Vim already installed.

some features of Vim-

  1. COMPLETION

2 . SPELL

3. CHECK

4. COMPARISON

5. MERGING GUI

6. PLUGINS

7. SYNTAX

8.HIGHLIGHTING

…and many more

To Find Vim Folder — ls -ltr /etc/alternatives/vi

Output — lrwxrwxrwx 1 root root 18 Apr 24 02:06 /etc/alternatives/vi -> /usr/bin/vim.basic

If you are learning with us let us know by mentioning us on Twitter .

happy learning 😉

--

--