HOME  |    TRAINING  |   FREE TUTORIALS   |   JOBS
Find out more about our new RSS feed.
FREE Tutorial
LINUX - THE VI EDITOR

CATEGORY
SEARCH OUR OTHER TUTORIALS

DESCRIPTION

vi is a screen-oriented display editor. It offers a powerful set of text editing operations based on a set of mnemonic commands. Most commands are single keystrokes that perform simple editing functions.
Click here to be kept informed of our new Tutorials.


TUTORIAL TAKEN FROM COURSE : LINUX USER INTRODUCTION

FULL COURSE DETAILS

This course covers the competencies and skills identified as key to intending Linux users. The course aims are to give readers sufficient skills to allow them to run applications in a Linux environment and the associated procedures this requires, such as organising, copying, moving and deleting files. Providing hands-on experience, on completion of the course the reader will be able to: understand the concepts underlying Linux and the benefits offered; be able to log on and off the system and run their chosen applications; be able to manage their files; and be able to use a variety of commands, tools and utilities.

TO ACCESS THE FULL COURSE AND HUNDREDS OF OTHERS, CLICK HERE.


vi displays a full screen window into the file you are editing. The contents of this window can be changed quickly and easily within vi. While editing, visual feedback is provided (the name vi itself is short for visual).

vi is one of three standard editors on the Linux system, the other two being:

  • ed - This is a line editor. While powerful in its own right, it is tedious to use.
  • ex - This is another line editor, but with the same powers and commands as vi: the names vi and ex - identify a particular user interface rather than any underlying functional difference.

In both ex and ed, visual updating of the terminal screen is limited, and commands are entered on a command line. vi, on the other hand, is a screen-oriented editor designed so that what you see on the screen corresponds exactly and immediately to the contents of the file you are editing.

Linux offers further editors, such as joe, pico and emacs (although the latter has been available for some years before Linux was created). Although both joe and pico are relatively easy to use, this course only looks at the vi editor, because of its power and flexibility and also because it is an industry standard that is widely available, not only on Linux and Unix, but also on other operating systems.

Starting vi

The syntax of the vi command is:

vi [file . . .]

vi performs no editing operations on the file that you name during invocation. Instead, it works on a copy of the file in an editing buffer. When you invoke vi with a single filename argument, the named file is copied to a temporary editing buffer. The editor remembers the name of the file specified at invocation, so that it can later copy the editing buffer back to the named file. The contents of the named file are not affected until the changes are copied back to the original file.

Exiting vi

There are several ways to exit the editor:

  • ZZ The editing buffer is written to the file only if any changes were made.
  • :x The editing buffer is written to the file only if any changes were made.
  • :q! Cancels an editing session. The exclamation mark ( !) tells vi to quit unconditionally. In this case, the editing buffer is not written out. If no alterations have been made to the file, the exclamation mark may be omitted.

The quit command may be combined with the write command - :w - to produce an alternative to ZZ:

:wq Write and quit.

Modes of Operation

Within vi there are three distinct modes of operation:

  • Command Mode
    Within Command Mode, signals from the terminal are interpreted as editing commands.
  • Edit Mode
    This mode can be entered by typing any of the vi insert, append, open, substitute, change, or replace commands. Once in insert mode, letters typed at the keyboard are inserted into the editing buffer.
  • ex Escape Mode
    The vi and ex editors are one and the same editor differing mainly in their user interface. In vi, commands are usually single keystrokes. In ex, commands are lines of text terminated by a Return. vi has a special escape command that gives access to many of these line-oriented ex commands. To use the ex escape mode, type a colon (:). The colon is echoed on the status line as a prompt for the ex command. Most file manipulation commands are executed in ex escape mode.

Command Mode

Cursor Movement

The cursor movement keys allow you to move your cursor around in a file:

Forward Space: l, Spacebar or arrow key

They move the cursor forward one character, along the line it is on. If the cursor is moved to the end of the present line, using one of these keys, further use will not affect the cursor position.

If a number is entered before the key is pressed, the movement will be that number of spaces. For example: 25Spacebar moves the cursor 25 characters forward.

Backspace: h, Backspace or arrow key

They move the cursor backward one character, along the line it is on. If the cursor is moved to the beginning of the present line, using one of these keys, further use will not affect the cursor position.

If a number is entered before the key is pressed, the movement will be that number of spaces. For example: 25Backspace moves the cursor 25 characters backward.

Next Line: +, Return, j, Ctrl -n or arrow key

+ and Return
move the cursor down to the beginning of the next line.

j, Ctrl - n and the arrow key
move the cursor down one line, remaining in the same column.

If a number is entered before the key is pressed, the movement will be that number of lines. For example: 25j moves the cursor 25 lines downward.

Previous Line: -, k, Ctrl -p or arrow key

-
moves the cursor up to the beginning of the next line.

k, Ctrl - p and the arrow key
move the cursor up one line, remaining in the same column.

If a number is entered before the key is pressed, the movement will be that number of lines. For example: 25k moves the cursor 25 lines upward.

Continued...


NEXT PAGE



10 RELATED COURSES AVAILABLE
LINUX FUNDAMENTALS
This course covers the competencies and skills identified as key to intending Linux users and developers. The cou....
LINUX USER INTRODUCTION
This course covers the competencies and skills identified as key to intending Linux users. The course aims are to....
LINUX OVERVIEW
To provide technical users new to Linux with a sound appreciation of the operating system. The course provides re....
UNIX NETWORKING ADMINISTRATION INTRODUCTION
Following the UNIX International Courseware Accreditation standards, this course covers the competencies and the ....
UNIX SYSTEM ADMINISTRATION SVR3
This course covers the competencies and skills identified as key to Unix System administrators. The course intro....
 
1 RELATED JOBS AVAILABLE
UNIX, LINUX (HIGH AVAILABILITY CLUSTERS) & QNX SYSTEMS ADMIN N/WEST
Computer Futures Solutions are seeking an experienced Linux/Unix/QNX Systems Administrator with a knowledge of Ne....
CONTACT US
Friday 10th February 2012  © COPYRIGHT 2012 - website design by Website Design by Visualsoft