Thursday, 27 August 2015

VI Editor in Linux - 1





Introduction to vi Editor 


  • Full-screen editor
  • Two modes of operation: command and text
  • Utilizes one letter commands
  • Does not format text
  • Flexible search and replace facility with pattern matching
  • Allows for user-defined editing functions using macros

Modes of Operation



The vi editor has two modes of operation. Command mode allows the user to perform
operations on the text, such as cut, paste, cursor movement, and replacement. These
operations are all invoked by one character “commands.” Text mode (also known as
insert mode) allows the user to enter text; all characters typed are inserted into the file.

There is no way to tell which mode the editor is in, other than pressing a key on the
keyboard. If the key you press is inserted into the file, the current mode is text mode. If
the key performs an action, the current mode is command mode.

Switching from command mode to text mode is done with one of the insert text
commands, which will be covered later. Returning to command mode is done by
pressing the <Esc> key.


Starting vi 


$ vi filename
  • If the file "filename" does not exist, it will be created
  • Otherwise, vi will open the existing file
When a session is initiated, one of two things happens:
  • If the file to be edited exists, a copy of the file is put into a buffer in temporary by default.
  • If the file does not exist, an empty buffer is opened for this session.
The tilde characters represent empty lines in the editor.  The editor starts in command mode.