Objective 8: Perform Basic File Editing Operations Using vi

vi is perhaps the most ubiquitous text editor available on Linux systems. Since most system administration tasks eventually require editing text files, being able to work effectively in vi essential.

This Objective concentrates on a subset of vi functionality. Learning the vi Editor (O'Reilly) is an indispensable reference for anyone interested in learning more about vi and the enhancements available in the various implementations of vi. There is also a large amount of documentation available at http://vimdoc.sourceforge.net and http://www.vim.org for the popular vi implementation Vim, most of which is applicable to any version of vi.

Invoking vi

To start vi, simply execute it. You will be editing a temporary file. To directly edit one or more files, give the names of the files on the command line:

$ vi file1.txt file2.txt

You are presented with a main window showing the contents of file1.txt, or if the specified files don't already exist, a blank screen with tilde (~) characters running the length of the left column (they indicate areas of the screen containing no text, not even blank lines).

vi Basics

The vi editor has two modes of operation: command or insert. In command mode, vi allows you to navigate around your file and enter commands. To enter new text, put vi into insert mode. In command mode, the keyboard keys are interpreted as vi commands instead of text. The convenience of being able to manipulate the editor without ...

Get LPI Linux Certification in a Nutshell, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.