Home Tech and Gadgets

How to Use Vi Editor

Vi Editor

On almost every Unix system one is likely to find a Vi editor. Vi stands for “visual editor” and it makes a display of a window inside the file that is being edited and shows twenty four text lines. Basically vi is among the text editors of the computer. With vi one is able to change, delete and add text. The application however does not provide formatting capabilities like indenting paragraphs and centering lines. Due to the fact that vi does not need function keys and arrow keys, it can be used on any kind of terminal. Vi editor uses the common alphabetical keys to execute commands. Vi editor deals with the closing and opening of files, the moving within a file as well as elementary editing.

Vi Editor

How to Start Vi

  • Type vi filename to open an existing file where “file name” is the existing file’s name and if the file is not included in the current directory, use the pathname.
  • Create a fresh file by simply typing vi newname and the latter is the new file’s name.
  • To open a “testvi” file type vi testvi
  • Blank lines will appear on the screen each bearing a tilde on the left as well as a line below thus giving the new file’s status and name.

Modes of Vi

Command mode is one of vi’s modes and it entails keyboard letters performing the editing functions and you can enter it by pressing< Esc> key.

The insert mode is the second one and it entails the typed letters forming sentences and words.

How to Enter Text

To start entering in the empty file one needs to change to insert mode from command mode to insert mode and this is done by typing i.

Type several short lines and then press <Return> when each line ends. Incase of lengthy lines the vi will not word wrap; it just breaks the line at the screen’s edge.

Incase of a mistake press <Delete> or < Backspace> to undo it depending on the terminal you have.

Cursor Moving

In order to move a cursor you have to go to command mode. To go back to command mode press <Esc>. Four keys are used to control the cursor and they are l, k, h and j.

Basic Editing

To execute editing commands you need to be in command mode. Editing commands have different functions that are determined by if they have been typed using lowercase or upper case.

Deleting

To remove a character move your cursor it reaches the wrong letter then go on to type x and if there are 4 characters type 4x. To delete words the cursor should be moved to the word’s first letter and then type dw. Vi helps in easy usage of the system and one can easily undo mistakes that might have been done during the process of editing.

Exit mobile version