vi text editor basics – P1

vi text editor basics – P1

Spread the love

If you deal with recent versions of Linux you might use an enhanced version of improved vi text editor vim. it has a lot of improvement. however, This article focus on the original vi that is found in UNIX machines. So, we will discuss how to use the Linux vi text editor. in addition, explain vi mechanism. if you already know how it works, then you might want to read its man pages.

vi a powerful text editor.

once you know vi, you can edit files really quickly, as it is extremely economical with the keystrokes. Due to its different modes for inserting and issuing commands, it is much faster than most non-mode based editors. also, It is a very small editor. nevertheless, it can do almost anything, as long as you know how to get it to do what you want

The 3 Modes of VI

The first thing most users learn about the VI editor is that it has three modes command, insert, and execute.

1 – Command Mode

allows the entry of commands to manipulate text. for example, copy, delete, past, cut …etc.. These commands are usually one or two characters long and can be entered with few keystrokes.

2 – Edit Mode (vi Insert mode).

puts anything typed on the keyboard into the current file. in other words, act like a normal text editor and insert text …etc

3 – vi Execute Mode

Commands Used to do multiple operations. for example, save files, quite the editor, search file content, or open a file … etc.

Switch vi modes

into insert mode

VI starts out in command mode. There are several ways to switch vi mode to insert mode and add texts.

The most commonly used command to get into insert mode is by pressing on the letter a or letter i. These two commands are described below.

Get back to command mode

Most commands are one character long, including those which use control characters. Once you are in insert mode, you get out of it and return to command mode by pressing the escape key.  If your terminal does not have an escape key, ^[ should work ( control + [ ). basically, You can hit escape twice in a row and VI would definitely return to command mode.

Hitting escape while you are already in command mode doesn’t take the editor out of command mode. It may beep to tell you that you are already in that mode.

Save and Exist vi, here an example,

– to switch to vi execute mode, firstly, you must be in command mode. then, press or type Colon “:“. after that, add the letter related to command to be executed. for example

to save the changes, type :w then press enter.

to quite without saving type :q! then press enter.

So, If I want to save my changes and close the editor. I will follow these steps

  1. Press escape twice to make sure that I am in command mode.
  2. Type colon : and wq .so the final look is “:wq”.

Conclusion, vi Linux editor is a powerful tool. hence, as an administrator, you should know vi editor basics.